Skip to Content
Nextra 4.0 is released 🎉

Terminal emulation has limited capabilities. Copy, paste, history, colorization, and completion all work, but not as seamlessly as in a real shell. For a smoother experience, you may want to try the demo locally:

npm i -g tsargp && complete -C tsargp tsargp

Try it out

Basic commands

  • clear clear the screen
  • tsargp -h print the help message
  • tsargp ... play with option values
  • tsargp view the options’ default values

Expected output

{ boolean: false, strRegex: "123456789", numRange: -1.23, strArray: [ "one" ], numArray: [ 1, 2 ], }

Word completion

  • check if completion works by pressing <Tab> (it behaves slightly differently than a real bash)
  • check if option names get completed (e.g., <Tab>, --<Tab>, --h<Tab>)
  • check if option parameters get completed (e.g., -b <Tab>, -sc <Tab>, -nc=<Tab>)

Positional arguments

  1. check if positional arguments can be specified before named ones (e.g., two -sr 0)
  2. check if arguments after the positional marker are recognized as positional (e.g., -- -f)

Expected output (1)

{ ... strRegex: "0", strArrayLimit: [ "two" ], ... }

Expected output (2)

{ ... strArrayLimit: [ "-f" ], ... }

Cluster arguments

  • check if cluster arguments can be specified (e.g., -sn 1 -1 or -s 1 -n -1)
  • check if cluster arguments can be specified with inline parameters (e.g., -s1 -n-1; same result as above)

Expected output

{ ... strRegex: "1", numRange: -1, ... }

Selection constraints

  1. check if a string parameter matches the required regex (e.g., try -sr A and see that it fails)
  2. check if a string parameter matches one of the choices (e.g., try -sc A and see that it fails)
  3. check if a number parameter matches the required range (e.g., try -n-3 and see that it fails)
  4. check if a number parameter matches one of the choices (e.g., try -nc=0 and see that it fails)
  5. check if a boolean parameter gets normalized and mapped correctly (e.g., -b No -sc one )

Expected output (1)

Invalid parameter to -sr: 'A'. Value must match the regex /^\d+$/.

Expected output (2)

Invalid parameter to -sc: 'A'. Value must be one of: 'one', 'two'.

Expected output (3)

Invalid parameter to -nr: '-3'. Value must be within the range [-2, Infinity].

Expected output (4)

Invalid parameter to -nc: '0'. Value must be one of: '1', '2'.

Expected output (5)

{ ... boolean: false, ... }

Array constraints

  1. check if the element count is limited to a certain amount (e.g., -- a b c d)
  2. check if duplicate values get removed (e.g., --numArrayUnique 1,2,1,2)

Expected output (1)

Option --strArrayLimit has too many values: 4. Should have at most 3.

Expected output (2)

{ ... numArrayUnique: [ 1, 2 ], ... }

Value replacement

When an option is specified more than once, the retained value is usually the last occurrence.

  1. check if values get overridden for a single-valued option (e.g., -sr 1 -nr 1 -sr 2 -nr 2)
  2. check if values get overridden for an array-valued option (e.g., abc -- def)
  3. check if values get appended for an array-valued option that is configured that way (e.g., --numArrayUnique 1 --numArrayUnique 2)

Expected output (1)

{ ... strRegex: "2", numRange: 2, ... }

Expected output (2)

{ ... strArrayLimit: [ "def" ], ... }

Expected output (3)

{ ... numArrayUnique: [ 1, 2 ], ... }

Inline parameters

  1. check if parameters can be inlined with option names (e.g., -sa=abc)
  2. check if inline parameters can contain equal signs (e.g., -sa==a=b)
  3. check if inline parameters are disallowed for an option (e.g., -sc=one)
  4. check if inline parameters are required for an option (e.g., -nc 1)

Expected output (1)

{ ... strArray: [ "abc" ], ... }

Expected output (2)

{ ... strArray: [ "=a=b" ], ... }

Expected output (3)

Option -sc does not accept inline parameters.

Expected output (4)

Option -nc requires an inline parameter.

Help option

  1. check if the help option accepts option filters (e.g., -h -f)
  2. check if the help option accepts a subcommand name (e.g., -h hello)
  3. check if the above can be combined (e.g., -h hello -h)

Expected output (1)

Argument parser for TypeScript. -f, --no-flag A flag option. Deprecated for some reason. Usage: demo.js [(-f|--no-flag)] ...

Expected output (2)

Usage: demo.js [<param>...] [(-h|--help)] [hello ...] Arguments: <param>... Accepts multiple parameters. Accepts positional arguments. Reads data from standard input. Defaults to ['world']. ...

Expected output (3)

Usage: demo.js [(-h|--help)] Options: -h, --help The help option for the hello command. Prints this help message. Uses the remaining arguments as option filter.

Requirements

  1. check th the -b option cannot be specified without required options (e.g., try -b yes and see that it fails)
  2. check if the -b option can be specified with required options (e.g., -b yes -sc one)
  3. check if the -b option can be specified through an environment variable (e.g., BOOLEAN=yes ...; same result as above)

Expected output (1)

Option -b requires (-sc or -sa == ['a', 'b']).

Expected output (2)

{ ... boolean: true, strChoice: "one", ... }

Miscellaneous

  1. check if the -f option can be specified without a parameter (also, see the warning produced)
  2. check if the -f option can be negated with --no-flag (also, see the warning produced)
  3. check if similar option names are suggested for an unknown option (e.g., -sr -s)

Expected output (1)

Option -f is deprecated and may be removed in future releases. { flag: true, ... }

Expected output (2)

Option --no-flag is deprecated and may be removed in future releases. { flag: false, ... }

Expected output (3)

Unknown option -s. Similar names are: -sr, -sc, -sa.

Subcommands

Open the browser console with F12, to see the messages logged by the subcommand.

  • check if the hello subcommand prints its arguments on the console
  • check if the hello subcommand can have its own options (e.g., hello -h)
    • in this help message, see that a positional option can have no name
  • check if the hello subcommand can be specified recursively (e.g., hello a hello b c hello)

Text wrapping

With the console panel open, slide the screen splitter until the terminal width changes, then run the help option.

  • check if words in the options’ descriptions get wrapped correctly
  • check if words in the usage section get wrapped correctly
  • check if words in the footer do not get wrapped (because it was configured that way)

Toggle styles

  • check if styles can be omitted with NO_COLOR (e.g., NO_COLOR=1 ...)
  • check if styles are emitted with FORCE_COLOR (e.g., NO_COLOR=1 FORCE_COLOR=1 ...)
  • check if styles are emitted when resetting (e.g., NO_COLOR= FORCE_COLOR= ...)
Last updated on