-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command aliases #125
Comments
@rustyoz if you use viper you can register an alias https://github.com/spf13/viper#registering-and-using-aliases |
On a related note, you can define aliases in the sense that
Perhaps there is a way to discover which command has been used, and then continue on from there? |
@rustyoz I am sure this is not ideal but this one way of achieving the same desired effect. var Verbose bool
var subCmd = &cobra.Command{
Use: "sub [no options!]",
Short: "My sub command",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Inside subCmd Run with args: %v\n", args)
if Verbose {
println("I am verbose")
}
},
}
subcmd.Flags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
var subAlias = &cobra.Command{
Use: "subAlias [no options!]",
Short: "alias for sub",
Run: func(cmd *cobra.Command, args []string) {
Verbose = true
subCmd.Run(cmd, args)
},
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would one go about creating a command that is an alias of another command with given flags?
for instance
program subcommand1 --flag1 --flag2 --flag3
can become
program subcommand2
The text was updated successfully, but these errors were encountered: