2025-03-14 21:59:59 -06:00
# getopt
> Parse command-line arguments.
2025-04-03 20:36:56 -06:00
> More information: <https://manned.org/getopt>.
2025-03-14 21:59:59 -06:00
- Parse optional `verbose` /`version` flags with shorthands:
2025-04-03 20:36:56 -06:00
`getopt {{[-o|--options]}} vV {{[-l|--longoptions]}} verbose,version -- --version --verbose`
2025-03-14 21:59:59 -06:00
- Add a `--file` option with a required argument with shorthand `-f` :
2025-04-03 20:36:56 -06:00
`getopt {{[-o|--options]}} f: {{[-l|--longoptions]}} file: -- --file=somefile`
2025-03-14 21:59:59 -06:00
- Add a `--verbose` option with an optional argument with shorthand `-v` , and pass a non-option parameter `arg` :
2025-04-03 20:36:56 -06:00
`getopt {{[-o|--options]}} v:: {{[-l|--longoptions]}} verbose:: -- --verbose arg`
2025-03-14 21:59:59 -06:00
- Accept a `-r` and `--verbose` flag, a `--accept` option with an optional argument and add a `--target` with a required argument option with shorthands:
2025-04-03 20:36:56 -06:00
`getopt {{[-o|--options]}} rv::s::t: {{[-l|--longoptions]}} verbose,source::,target: -- -v --target target`