clap/examples/23_flag_subcommands_pacman.md
Ed Page bfa02fd418 test: More thoroughly test examples
This ports our example testing over to [trycmd](https://docs.rs/) so
we can:
- More thoroughly test our examples
- Provide always-up-to-date example usage

The old way of testing automatically picked up examples.  This new way
requires we have a `.md` file that uses the example in some way.

Notes:
- Moved overall example description to the `.md` file
- I added cross-linking between related examples
- `14_groups` had a redundant paragraph (twice talked about "one and
  only one"
2021-11-23 13:13:41 -06:00

1.1 KiB

This feature allows users of the app to pass subcommands in the fashion of short or long flags. You may be familiar with it if you ever used pacman. Some made up examples of what flag subcommands are:

Here, -S is a short flag subcommand:

$ 23_flag_subcommands_pacman -S package
Installing package...

Here --sync is a long flag subcommand:

$ 23_flag_subcommands_pacman --sync package
Installing package...

Now the short flag subcommand (-S) with a long flag:

$ 23_flag_subcommands_pacman -S --search name
Searching for name...

And the various forms of short flags that work:

$ 23_flag_subcommands_pacman -S -s name
Searching for name...
$ 23_flag_subcommands_pacman -Ss name
Searching for name...

(users can "stack" short subcommands with short flags or with other short flag subcommands)

NOTE: Keep in mind that subcommands, flags, and long flags are case sensitive: -Q and -q are different flags/subcommands. For example, you can have both -Q subcommand and -q flag, and they will be properly disambiguated. Let's make a quick program to illustrate.