package cmd import "go.fifitido.net/cmd/flags" type Option func(*Command) func WithShortDescription(s string) Option { return func(c *Command) { c.shortDescription = s } } func WithLongDescription(s string) Option { return func(c *Command) { c.longDescription = s } } func WithArgument(name string, required bool) Option { return func(c *Command) { c.arguments = append(c.arguments, &Argument{name, required}) } } func WithArguments(args ...*Argument) Option { return func(c *Command) { c.arguments = append(c.arguments, args...) } } func WithFlag(f flags.Flag) Option { return func(c *Command) { c.flags = append(c.flags, f) } } func WithFlags(fs ...flags.Flag) Option { return func(c *Command) { c.flags = append(c.flags, fs...) } } func WithSubcommand(s *Command) Option { return func(c *Command) { c.subcommands.Add(c) s.parent = c } } func WithSubcommands(ss ...*Command) Option { return func(c *Command) { c.subcommands.Add(c) for _, s := range ss { s.parent = c } } } func WithParent(p *Command) Option { return func(c *Command) { c.parent = p p.subcommands.Add(c) } } func WithRunFunc(r func(args []string)) Option { return func(c *Command) { c.run = r } } func WithRunErrFunc(r func(args []string) error) Option { return func(c *Command) { c.run = func(args []string) { if err := r(args); err != nil { panic(err) } } } }