2021-11-30 12:30:19 -06:00
[`pacman` ](https://wiki.archlinux.org/index.php/pacman ) defines subcommands via flags.
2021-11-10 16:15:30 -06:00
Here, `-S` is a short flag subcommand:
2022-01-05 17:54:33 +01:00
```console
2021-11-30 12:30:19 -06:00
$ pacman -S package
2021-11-10 16:15:30 -06:00
Installing package...
2022-01-05 17:54:33 +01:00
2021-11-10 16:15:30 -06:00
```
Here `--sync` is a long flag subcommand:
2022-01-05 17:54:33 +01:00
```console
2021-11-30 12:30:19 -06:00
$ pacman --sync package
2021-11-10 16:15:30 -06:00
Installing package...
2022-01-05 17:54:33 +01:00
2021-11-10 16:15:30 -06:00
```
Now the short flag subcommand (`-S` ) with a long flag:
2022-01-05 17:54:33 +01:00
```console
2021-11-30 12:30:19 -06:00
$ pacman -S --search name
2021-11-10 16:15:30 -06:00
Searching for name...
2022-01-05 17:54:33 +01:00
2021-11-10 16:15:30 -06:00
```
And the various forms of short flags that work:
2022-01-05 17:54:33 +01:00
```console
2021-11-30 12:30:19 -06:00
$ pacman -S -s name
2021-11-10 16:15:30 -06:00
Searching for name...
2022-01-05 17:54:33 +01:00
2021-11-30 12:30:19 -06:00
$ pacman -Ss name
2021-11-10 16:15:30 -06:00
Searching for name...
2022-01-05 17:54:33 +01:00
2021-11-10 16:15:30 -06:00
```
*(users can "stack" short subcommands with short flags or with other short flag subcommands)*
2022-02-14 11:51:01 -06:00
In the help, this looks like:
```console
$ pacman -h
package manager utility
2022-09-07 11:03:55 -05:00
Usage: pacman[EXE] < COMMAND >
2022-02-14 11:51:01 -06:00
2022-08-30 21:38:37 -05:00
Commands:
2022-09-19 09:07:37 -05:00
query, -Q, --query Query the package database.
sync, -S, --sync Synchronize packages.
help Print this message or the help of the given subcommand(s)
2022-02-14 11:51:01 -06:00
2022-08-26 10:59:27 -05:00
Options:
2022-09-07 15:29:15 -05:00
-h, --help Print help information
-V, --version Print version information
2022-08-26 10:59:27 -05:00
2022-02-14 11:51:01 -06:00
$ pacman -S -h
Synchronize packages.
2022-09-07 11:03:55 -05:00
Usage: pacman[EXE] {sync|--sync|-S} [OPTIONS] [package]...
2022-02-14 11:51:01 -06:00
2022-08-26 09:40:23 -05:00
Arguments:
2022-09-07 15:29:15 -05:00
[package]... packages
2022-02-14 11:51:01 -06:00
2022-08-26 09:40:23 -05:00
Options:
2022-09-07 15:29:15 -05:00
-s, --search < search > ... search remote repositories for matching strings
-i, --info view package information
-h, --help Print help information
2022-02-14 11:51:01 -06:00
```
And errors:
```console
$ pacman -S -s foo -i bar
? failed
error: The argument '--search < search > ...' cannot be used with '--info'
2022-09-07 11:03:55 -05:00
Usage: pacman[EXE] {sync|--sync|-S} --search < search > ... < package > ...
2022-02-14 11:51:01 -06:00
2022-09-15 14:22:28 -05:00
For more information try '--help'
2022-02-14 11:51:01 -06:00
```
2021-11-10 16:15:30 -06:00
**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.