cmdline
nimony/lib/std/cmdline.nim
This module contains system facilities for reading command line parameters.
proc parseCmdLine(c: string): seqSplits a
command line:idx: into several components.Note: This proc is only occasionally useful, better use the parseopt module.
On Windows, it uses the following parsing rules:
- Arguments are delimited by white space, which is either a space or a tab.
- The caret character (^) is not recognized as an escape character or
delimiter. The character is handled completely by the command-line parser in the operating system before being passed to the argv array in the program.
- A string surrounded by double quotation marks ("string") is interpreted
as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument.
- A double quotation mark preceded by a backslash (\") is interpreted as a
literal double quotation mark character (").
- Backslashes are interpreted literally, unless they immediately precede
a double quotation mark.
- If an even number of backslashes is followed by a double quotation mark,
one backslash is placed in the argv array for every pair of backslashes, and the double quotation mark is interpreted as a string delimiter.
- If an odd number of backslashes is followed by a double quotation mark,
one backslash is placed in the argv array for every pair of backslashes, and the double quotation mark is "escaped" by the remaining backslash, causing a literal double quotation mark (") to be placed in argv.
On Posix systems, it uses the following parsing rules: Components are separated by whitespace unless the whitespace occurs within
"or'quotes.See also:
- parseopt module
paramCount proc_paramStr proc_commandLineParams proc_
proc paramStr(i: int64): stringproc paramCount(): int64proc commandLineParams(): seqConvenience 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:
- parseopt module
parseCmdLine proc_paramCount proc_paramStr proc_- getAppFilename proc
Examples:
nim when declared(commandLineParams): # Use commandLineParams() here else: # Do something else!