Wolfram/ CommandLineParser

Parser for command line arguments

Contributed by: Matteo Salvarezza

A small package to parse command line arguments in a Wolfram Language script.

Installation Instructions

To install this paclet in your Wolfram Language environment, evaluate this code:
PacletInstall["Wolfram/CommandLineParser"]


To load the code after installation, evaluate this code:
Needs["Wolfram`CommandLineParser`"]

Details

The functionality offered by this paclet can be divided in two parts:

A very flexible command line parsing logic that allows for arbitrary validation/transformation of provided data using low-level argument specifications
A set of high-level helpers to generate said low-level specifications for common use cases (numeric arguments, boolean arguments, ...)

Examples

Basic Examples

Specify a command line interface with a single numeric argument:

In[1]:=
argsSpec = {{"my-int-arg" -> NumericSpec["Integer", "An unbounded integer"]}, {}};

Parse settings according to the above specification:

In[2]:=
ParseCommandLine[argsSpec, {"42"}]
Out[2]=

ParseCommandLine is meant to be used in Wolfram Language scripts. In the above example command line arguments are explicitly provided as a list of strings, but it's not necessary to do so in a script. When ParseCommandLine is used in a script, its 1-argument form will automatically grab the arguments provided from the command line. When ran from a notebook interface the 1-argument form does not work:

In[3]:=
ParseCommandLine[argsSpec]
Out[3]=

See the Tech Notes for the full documentation

Compatibility

Wolfram Language Version 13.0

Version History

  • 1.0.2 – 19 March 2024
  • 1.0.1 – 18 March 2024
  • 1.0.0 – 18 March 2024

License Information

MIT License

Paclet Source