Parse command-line arguments: Difference between revisions
Content deleted Content added
No edit summary |
Added Prolog |
||
Line 476: | Line 476: | ||
{"C:\\Program Files (x86)\\Phix\\test.exe","C:\\Program Files (x86)\\Phix\\test.exe","nc","-v","-n","-z","-w","1","192.168.1.2","1-1000"} |
{"C:\\Program Files (x86)\\Phix\\test.exe","C:\\Program Files (x86)\\Phix\\test.exe","nc","-v","-n","-z","-w","1","192.168.1.2","1-1000"} |
||
</pre> |
</pre> |
||
=={{header|Prolog}}== |
|||
Works in SWI-Prolog. |
|||
<lang Prolog>:- initialization(main, main). |
|||
main(Argv) :- |
|||
opt_spec(Spec), |
|||
opt_parse(Spec, Argv, Opts, _), |
|||
( |
|||
member(help(true), Opts) -> show_help |
|||
; maplist(format('~w~n'), Opts) |
|||
). |
|||
show_help :- |
|||
opt_spec(Spec), |
|||
opt_help(Spec, HelpText), |
|||
write('Usage: swipl opts.pl <options>\n\n'), |
|||
write(HelpText). |
|||
opt_spec([ |
|||
[opt(help), |
|||
type(boolean), |
|||
default(false), |
|||
shortflags([h]), |
|||
longflags([help]), |
|||
help('Show Help')], |
|||
[opt(noconnect), |
|||
type(boolean), |
|||
default(false), |
|||
shortflags([n]), |
|||
longflags([noconnect]), |
|||
help('do not connect, just check server status')], |
|||
[opt(server), |
|||
type(atom), |
|||
default('www.google.com'), |
|||
shortflags([s]), |
|||
longflags([server]), |
|||
help('The server address.')], |
|||
[opt(port), |
|||
type(integer), |
|||
default(5000), |
|||
shortflags([p]), |
|||
longflags([port]), |
|||
help('The server port.')] |
|||
]).</lang> |
|||
{{out}} |
|||
<lang Powershell> |
|||
# no options set (use defaults) |
|||
$ swipl .\opts.pl |
|||
help(false) |
|||
noconnect(false) |
|||
server(www.google.com) |
|||
port(5000) |
|||
# setting various options |
|||
$ swipl .\opts.pl --server www.test.com -p 2342 -n |
|||
help(false) |
|||
server(www.test.com) |
|||
port(2342) |
|||
noconnect(true) |
|||
# show help |
|||
$ swipl .\opts.pl -h |
|||
Usage: swipl opts.pl <options> |
|||
--help -h boolean=false Show Help |
|||
--noconnect -n boolean=false do not connect, just check server status |
|||
--server -s atom=www.google.com The server address. |
|||
--port -p integer=5000 The server port. |
|||
</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |