Options and Operands in a Command
Options commonly choose behavior or set values, while operands supply objects such as input paths. An interface must document the actual syntax it accepts.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Identify input roles
A report command may accept a format option and one source filename. Sending two filenames can be invalid even if both exist. Its input contract governs accepted argument counts and roles.
Treat leading punctuation deliberately
A command supporting a double-dash option delimiter can then receive names whose first character could otherwise mark an option. Test names with spaces and punctuation under argument construction rules.[1]
Read one token according to the tool's argument grammar
A tool may accept --width 80 notes.txt where width consumes the following token and the final token names a file. If it supports an end-of-options marker, a file with a leading dash can be handled as an operand after that marker. Consult the tool's grammar. See reading command help.
Tool grammar: --width NUMBER followed by FILE
In "--width 80 notes.txt", 80 is the option's value
In "-- -notes.txt", the leading-dash name is an operand for tools implementing --
Include one malformed option in your test
An option missing its value should report the option itself, while a missing file can be diagnosed later. Test a file name that resembles an option and confirm the exact received arguments.