Skip to content

Commit

Permalink
Add an example of slice flags to the subcommands demo (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess authored Feb 5, 2025
1 parent 291899f commit cddec6a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
Binary file modified docs/img/namedargs.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/quickstart.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/subcommands.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion examples/subcommands/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type sayOptions struct {
thing string
count int
shout bool
items []string
}

func buildSayCommand() (*cli.Command, error) {
Expand All @@ -39,6 +40,7 @@ func buildSayCommand() (*cli.Command, error) {
cli.Flag(&options.shout, "shout", 's', false, "Say the message louder"),
cli.Flag(&options.count, "count", 'c', 0, "Count the things"),
cli.Flag(&options.thing, "thing", 't', "", "Name of the thing"),
cli.Flag(&options.items, "item", 'i', nil, "Items to add to a list"),
)
}

Expand Down Expand Up @@ -77,7 +79,13 @@ func runSay(options *sayOptions) func(cmd *cli.Command, args []string) error {
fmt.Fprintln(cmd.Stdout(), arg, " ")
}
}
fmt.Printf("Shout: %v\nCount: %v\nThing: %v\n", options.shout, options.count, options.thing)
fmt.Printf(
"Shout: %v\nCount: %v\nThing: %v\nItems: %v\n",
options.shout,
options.count,
options.thing,
options.items,
)
fmt.Fprintln(cmd.Stdout())
return nil
}
Expand Down

0 comments on commit cddec6a

Please sign in to comment.