Parse command-line arguments: Difference between revisions

Added Wren
No edit summary
(Added Wren)
Line 1,170:
Searching with -regexp allows to specify longer mnemonic names, so it still succeeds on longer flags, e.g.
$ myscript.tcl -separator '\t' ...
 
=={{header|Wren}}==
Any command line arguments passed to a Wren CLI script are collected in the same order into a list of strings. If individual arguments require any further parsing, this can then be done using normal Wren code.
<lang ecmascript>import "os" for Process
 
var args = Process.arguments
System.print("The arguments passed are: %(args)")
// parse last argument to a Range object
var sp = args[-1].split("-")
var start = Num.fromString(sp[0])
var end = Num.fromString(sp[1])
var r = start..end
System.print("The final argument expressed as a Range object is %(r)")</lang>
 
{{out}}
<pre>
$ wren_cli parse_command-line_arguments.wren -v -n -z -w 1 192.168.1.2 1-1000
 
The arguments passed are: [-v, -n, -z, -w, 1, 192.168.1.2, 1-1000]
The final argument expressed as a Range object is 1..1000
</pre>
 
=={{header|zkl}}==
9,476

edits