How to get access to command-line arguments in Nim?
Personally I find paramCount
and paramStr
a bit confusing to work with, because the paramCount
value differs from C conventions (see the document links).
Fortunately, there are additional convenient functions which do not require to be aware of the conventions:
commandLineParams
returns aseq
of only command line params.getAppFilename
returns the executable file name (what isargv[0]
in the C world).
Here's an example that prints the number of arguments and the first argument:
import os
echo paramCount(), " ", paramStr(1)