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:
var createCmd = &cobra.Command{
Use: "create <name>",
Short: "Create a thing",
Long: "Create a thing",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.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!
Doing it manually in a (Pre)RunE is sadly the best you can likely do. Sorry.
No need to apologize! I was just looking for the recommended way to get stuff done. :smile: Thank you for the quick reply!
Most helpful comment
Doing it manually in a
(Pre)RunEis sadly the best you can likely do. Sorry.