Jump to content

Parse command-line arguments: Difference between revisions

no edit summary
m (→‎{{header|Raku}}: Fix comment: Perl 6 --> Raku)
No edit summary
Line 141:
verbose: true
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}}==
Elixir provides an option parser in a library module called <tt>OptionParser</tt>.
478

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.