Parse command-line arguments: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (added Arturo) |
(Added Ada solution) |
||
Line 8: | Line 8: | ||
Many languages provide a library (getopt or GetOpt) to parse the raw command line options in an intelligent way. |
Many languages provide a library (getopt or GetOpt) to parse the raw command line options in an intelligent way. |
||
<br><br> |
<br><br> |
||
=={{header|Ada}}== |
|||
<syntaxhighlight lang="ada"> |
|||
-- Show command-line arguments |
|||
-- J. Carter 2023 Apr |
|||
-- The task is called "Parse command-line arguments", but as parsing requires attaching meaning to arguments, and the task |
|||
-- specification does not do so, showing them is all we can reasonably do |
|||
with Ada.Command_Line; |
|||
with Ada.Text_IO; |
|||
procedure Show_Args is |
|||
-- Empty |
|||
begin -- Show_Args |
|||
All_Args : for Arg in 1 .. Ada.Command_Line.Argument_Count loop |
|||
Ada.Text_IO.Put_Line (Item => Arg'Image & ": " & Ada.Command_Line.Argument (Arg) ); |
|||
end loop All_Args; |
|||
end Show_Args; |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
$ ./show_args nc -v -n -z -w 1 192.168.1.2 1-1000 |
|||
1: nc |
|||
2: -v |
|||
3: -n |
|||
4: -z |
|||
5: -w |
|||
6: 1 |
|||
7: 192.168.1.2 |
|||
8: 1-1000 |
|||
</pre> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |