Skip to content

Commit

Permalink
feat: add vin command
Browse files Browse the repository at this point in the history
  • Loading branch information
5n7-sk committed Dec 3, 2020
1 parent 5486eaf commit 7fbf6c1
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 13 deletions.
37 changes: 37 additions & 0 deletions cmd/vin/cmd/cmd_completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var shell string

func runCompletion(cmd *cobra.Command, args []string) error {
switch shell {
case "bash":
return rootCmd.GenBashCompletion(os.Stdout)
case "fish":
return rootCmd.GenFishCompletion(os.Stdout, true)
case "powershell":
return rootCmd.GenPowerShellCompletion(os.Stdout)
case "zsh":
return rootCmd.GenZshCompletion(os.Stdout)
}
return fmt.Errorf("invalid shell: %s", shell)
}

var completionCmd = &cobra.Command{
Use: "completion",
Short: "Output shell completion (bash/fish/powershell/zsh)",
Long: "Output shell completion (bash/fish/powershell/zsh).",
RunE: runCompletion,
}

func init() { //nolint:gochecknoinits
completionCmd.Flags().StringVarP(&shell, "shell", "s", "bash", "shell type (bash/fish/powershell/zsh)")

rootCmd.AddCommand(completionCmd)
}
22 changes: 22 additions & 0 deletions cmd/vin/cmd/cmd_get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"github.com/skmatz/vin"
"github.com/spf13/cobra"
)

func runGet(cmd *cobra.Command, args []string) error {
cli := vin.NewCLI()
return cli.Run()
}

var getCmd = &cobra.Command{
Use: "get",
Short: "Get applications",
Long: "Get applications.",
RunE: runGet,
}

func init() { //nolint:gochecknoinits
rootCmd.AddCommand(getCmd)
}
31 changes: 31 additions & 0 deletions cmd/vin/cmd/cmd_root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var version bool

func runRoot(cmd *cobra.Command, args []string) error {
if version {
return runVersion(cmd, args)
}
return fmt.Errorf("vin requires a sub-command")
}

var rootCmd = &cobra.Command{
Use: "vin",
Short: "Vin is a next-generation GitHub Releases installer",
Long: "Vin is a next-generation GitHub Releases installer.",
RunE: runRoot,
}

func init() { //nolint:gochecknoinits
rootCmd.Flags().BoolVarP(&version, "version", "V", false, "show version")
}

func Execute() {
rootCmd.Execute() //nolint:errcheck
}
25 changes: 25 additions & 0 deletions cmd/vin/cmd/cmd_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var Version string

func runVersion(cmd *cobra.Command, args []string) error {
fmt.Printf("v%s\n", Version)
return nil
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Show version",
Long: "Show version.",
RunE: runVersion,
}

func init() { //nolint:gochecknoinits
rootCmd.AddCommand(versionCmd)
}
15 changes: 2 additions & 13 deletions cmd/vin/main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
package main

import (
"fmt"
"os"

"github.com/skmatz/vin"
"github.com/skmatz/vin/cmd/vin/cmd"
)

func run() error {
cli := vin.NewCLI()
return cli.Run()
}

func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
cmd.Execute()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ require (
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/mholt/archiver/v3 v3.5.0
github.com/spf13/cobra v1.1.1
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58
)
145 changes: 145 additions & 0 deletions go.sum

Large diffs are not rendered by default.

0 comments on commit 7fbf6c1

Please sign in to comment.