You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am migrating my app over from another cli library (kingpin), and one of the things they let me do is document positional arguments, e.g. cmd.Arg("name", "name of the thing").Required().StringVar(&name). I am having trouble understanding how to migrate that over. So far the best I have come up with is this:
varcreateCmd=&cobra.Command{
Use: "create <name>",
Short: "Create a thing",
Long: "Create a thing",
RunE: func(cmd*cobra.Command, args []string) error {
iflen(args) <1 {
returnerrors.New("The name argument is required")
}
name=args[0]
// create a thing
}
Basically I am documenting the arg in the Use string and then parsing the arg in RunE. This feels a bit awkward, is there something built-in that I am overlooking?
Thanks!
The text was updated successfully, but these errors were encountered:
I am migrating my app over from another cli library (kingpin), and one of the things they let me do is document positional arguments, e.g.
cmd.Arg("name", "name of the thing").Required().StringVar(&name)
. I am having trouble understanding how to migrate that over. So far the best I have come up with is this:Basically I am documenting the arg in the Use string and then parsing the arg in RunE. This feels a bit awkward, is there something built-in that I am overlooking?
Thanks!
The text was updated successfully, but these errors were encountered: