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 = append(c.subcommands, s) s.parent = c } } func WithSubcommands(ss ...*Command) Option { return func(c *Command) { c.subcommands = append(c.subcommands, ss...) } } func WithParent(p *Command) Option { return func(c *Command) { c.parent = p p.subcommands = append(p.subcommands, 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) } } } }