std/cmdline (original) (raw)

Source Edit

This module contains system facilities for reading command line parameters.See also:

Procs

proc commandLineParams(): seq[string] {....raises: [], tags: [ReadIOEffect], forbids: [].}

Convenience proc which returns the command line parameters.

This returns only the parameters. If you want to get the application executable filename, call getAppFilename().

Availability: On Posix there is no portable way to get the command line from a DLL and thus the proc isn't defined in this environment. You can test for its availability with declared().

See also:

Examples:

when declared(commandLineParams):

else:

Source Edit

proc paramCount(): int {....tags: [ReadIOEffect], raises: [], forbids: [].}

Returns the number of command line arguments given to the application.

Unlike argc in C, if your binary was called without parameters this will return zero. You can query each individual parameter with paramStr proc or retrieve all of them in one go with commandLineParams proc.

Availability: When generating a dynamic library (see --app:lib) on Posix this proc is not defined. Test for availability using declared().

See also:

Examples:

when declared(paramCount):

else:

Source Edit

proc paramStr(i: int): string {....tags: [ReadIOEffect], raises: [], forbids: [].}

Returns the i-th command line argument given to the application.

i should be in the range 1..paramCount(), the IndexDefect exception will be raised for invalid values. Instead of iterating over paramCount() with this proc you can call the convenience commandLineParams().

Similarly to argv in C, it is possible to call paramStr(0) but this will return OS specific contents (usually the name of the invoked executable). You should avoid this and call getAppFilename() instead.

Availability: When generating a dynamic library (see --app:lib) on Posix this proc is not defined. Test for availability using declared().

See also:

Examples:

when declared(paramStr):

else:

Source Edit

proc parseCmdLine(c: string): seq[string] {.noSideEffect, ...gcsafe, extern: "nos$1", raises: [], tags: [], forbids: [].}

Splits a command line into several components.

Note: This proc is only occasionally useful, better use the parseopt module.

On Windows, it uses the following parsing rules:

On Posix systems, it uses the following parsing rules: Components are separated by whitespace unless the whitespace occurs within " or ' quotes.

See also: