Parse command-line arguments: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: Fix comment: Perl 6 --> Raku) |
MaiconSoft (talk | contribs) No edit summary |
||
Line 141: | Line 141: | ||
verbose: true |
verbose: true |
||
color: no</pre> |
color: no</pre> |
||
=={{header|Delphi}}== |
|||
{{libheader| System.SysUtils}} |
|||
<lang Delphi> |
|||
program Parse_command_line_argument; |
|||
{$APPTYPE CONSOLE} |
|||
uses |
|||
System.SysUtils; |
|||
var |
|||
sfile, sLength: string; |
|||
verbose: boolean; |
|||
begin |
|||
if (ParamCount = 0) or (FindCmdLineSwitch('h', true)) then |
|||
begin |
|||
Writeln('Usage: -file {filename} -l {length} {-v}'#10); |
|||
Writeln('* filename: Name of file to process. Default "file.dat";'); |
|||
Writeln('* length: Max number of bytes to read (not optional);'); |
|||
Writeln('* -v (verbose): show information on terminal. Default "false"'); |
|||
end |
|||
else |
|||
begin |
|||
Assert(FindCmdLineSwitch('l', sLength), 'Length is not optional'); |
|||
if not FindCmdLineSwitch('file', sfile) then |
|||
sfile := 'file.dat'; |
|||
verbose := FindCmdLineSwitch('v', True); |
|||
Writeln('Variables states:'#10); |
|||
Writeln('File: ', sfile); |
|||
Writeln('Verbose: ', verbose); |
|||
Writeln('Length: ', sLength); |
|||
end; |
|||
Readln; |
|||
end.</lang> |
|||
{{out}} |
|||
Parse_command_line_argument.exe |
|||
<pre> |
|||
Usage: -file {filename} -l {length} {-v} |
|||
* filename: Name of file to process. Default "file.dat"; |
|||
* length: Max number of bytes to read (not optional); |
|||
* -v (verbose): show information on terminal. Default "false"</pre> |
|||
Parse_command_line_argument.exe -file main.c -v -l 10 |
|||
<pre> |
|||
Variables states: |
|||
File: main.c |
|||
Verbose: TRUE |
|||
Length: 10</pre> |
|||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
Elixir provides an option parser in a library module called <tt>OptionParser</tt>. |
Elixir provides an option parser in a library module called <tt>OptionParser</tt>. |