command-line-argumentsnim-lang

How to get access to command-line arguments in Nim?


How can I access command line arguments in Nim?

The documentation shows only how to run the compiled Nim code with command line arguments

nim compile --run greetings.nim arg1 arg2

but I didn't find how to use their values in code.


Solution

  • Here is an example that prints the number of arguments and the first argument:

    import std/os
    
    echo paramCount(), " ", paramStr(1)