Skip to content
Snippets Groups Projects
Commit dafdd8181250 authored by Christophe de Vienne's avatar Christophe de Vienne
Browse files

cmd.WithSubcommand now takes descriptions

parent 1d8b85be4337
No related branches found
No related tags found
No related merge requests found
Pipeline #121145 failed
...@@ -36,8 +36,10 @@ ...@@ -36,8 +36,10 @@
} }
type subcommand[E any] struct { type subcommand[E any] struct {
name string name string
init func(*Program[E]) any shortDescription string
longDescription string
init func(*Program[E]) any
} }
type Program[E any] struct { type Program[E any] struct {
...@@ -186,7 +188,10 @@ ...@@ -186,7 +188,10 @@
} }
} }
func WithSubcommand[E any](name string, init func(*Program[E]) any) Option[E] { func WithSubcommand[E any](
name string, shortDescription string, longDescription string,
init func(*Program[E]) any,
) Option[E] {
return func(program *Program[E]) { return func(program *Program[E]) {
program.setupSubcommands = append(program.setupSubcommands, subcommand[E]{ program.setupSubcommands = append(program.setupSubcommands, subcommand[E]{
name: name, name: name,
...@@ -279,7 +284,10 @@ ...@@ -279,7 +284,10 @@
} }
for _, subcmd := range program.setupSubcommands { for _, subcmd := range program.setupSubcommands {
if _, err := parser.AddCommand(subcmd.name, subcmd.name, "", subcmd.init(&program)); err != nil { if _, err := parser.AddCommand(
subcmd.name, subcmd.shortDescription, subcmd.shortDescription,
subcmd.init(&program),
); err != nil {
panic(err) panic(err)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment