Command Line Arguments in PureScript
Command-line arguments are a common way to parameterize execution of programs. For example, pulp run src/Main.purs
uses run
and src/Main.purs
arguments to the pulp
program.
To experiment with command-line arguments, it’s best to compile the program first:
In PureScript, we use the argv
function from the Node.Process
module to access command-line arguments. The drop 2
function is used to remove the first two elements (Node.js executable path and script path) from the argument list.
Note that in PureScript, array indexing with !!
returns a Maybe
type, so the output for the individual argument is wrapped in Just
.
Next, we’ll look at more advanced command-line processing with options parsing libraries in PureScript.