-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
263 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters