Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Command-Line Parsing

Guardian Tcl supports command-line parsing with Usage, a suite for parsing command line arguments and generating documentation from a spec that can be embedded as #USAGE comments in the top of a script file.

When run with the -U or --usage flag and a script, guarsh will use Usage to parse the script’s command-line arguments and store the results of this parse in the usage Tcl array. This is equivalent to the parsing done with usage bash, usage exec, or similar, with a few differences:

  • The results of parsing the arguments are stored in a Tcl array1 named usage instead of environment variables.
  • Repeated arguments are stored as Tcl lists instead of shell-quoted strings.
  • Boolean and count flags are always set in the array, with a value of 0 if they do not appear.

  1. Actually a dictionary in the usage variable, but in Jim Tcl arrays and dict variables are the same thing.