8000 GitHub - rdpate/clear-options: Clear command-line options and arguments
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

rdpate/clear-options

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Clear Options

At attempt to clarify option parsing for my own understanding.

  • argument -- a sequence of characters or bytes
  • option -- an argument that selects behavior of the program
  • option-argument -- an argument expected after and providing a value for an option
  • operand -- an argument that specifies input for the program; aka "non-option argument" or sometimes just "argument"

Categories

Short

  • exactly "-" is a non-option argument
  • short options prefixed with "-"
  • short options may have a value specified in the same argument after the option character

Long

  • long options prefixed with "--"
  • long options may have a value specified in the same argument separated by "="

Non-hyphen

  • generally rare
  • prefixes may be "@", "+", or others

Option-arguments

  • options may take one value in the immediately following argument
  • options may explicitly not take a value
  • short options are often allowed to be combined; eg. "-a -b" to "-ab"
    • impossible to parse without a spec

Options first

  • first non-option argument ends option processing
  • "--" is discarded and ends option processing

Interspersed

  • whenever the first non-option argument does not end option processing
  • however, "--" is discarded and still ends option processing

Alternate mode

  • options which select entirely separate behavior
  • common examples: help and version

Obfuscated

  • catch-all for everything not otherwise defined
  • could be broken down into more categories
  • notable examples: find, ps, dd

Guidelines for myself

Above all else, programs should have fewer options.

Consider evolution. In general, short options are the most convenient given sufficient familiarity, but are very limited and can be the least readable. Default to long options and assign short options with some thought.

Avoid non-hyphen options if at all possible. Avoid interspersed options for consistency with the (common) case of a program which has program-plus-arguments as arguments (eg. watch, daemontools). Avoid option-arguments as inflexible -- though POSIX prefers them.

Unsupplied values ("-a", "--b") should select the default for that option. Use a different option or a long option starting with "no-" to select non-defaults; eg. "--no-backup", or "--quiet" vs "--verbose". If no default is available (the value is required), then indicate that error. If the option is boolean (the value is prohibited), use a "no-" prefix rather than a value (eg. "--no-feat" rather than "--feat=no").

Reserve long options starting with "X-" (eg. "--X-abc") for options without a stable interface; ie. in testing or dev.

Avoid alternate mode options whenever an acceptable alternative exists. Single-file scripts benefit from --help, though perhaps a single comment block in the source would work just as well.

Unsorted:

  • option names start with an ASCII letter or number and contain only ASCII characters
  • short options have equivalent and indistinguishable long options; eg. "-a" / "--a", "-bv" / "--b=v"
  • never alias "--help" to "-h" -- short options are too handy for a rarely used option, no matter how useful
  • What is today "-v" might tomorrow become "-vvvv" because "v" was required to not take an option and it was combined with other options ("-avbc"). Backup options ("-b") might learn how to name files ("-bEXT"). Or "--verbose" might learn to filter categories ("--verbose=info,debug", "-vinfo,debug") instead of merely toggling a bool.

About

Clear command-line options and arguments

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0