[[Property:modification_date|Thu, 22 Nov 2018 19:50:45 GMT]]
[[Property:publication_date|Thu, 22 Nov 2018 19:50:45 GMT]]
[[Property:title|Example: Command line arguments]]
[[Property:weight|0]]
[[Property:uuid|ba852d83-3c02-4d38-088a-60b76fe5c63f]]
==Description==
Retrieve the list of command-line arguments given to the program.
Example command line:
myprogram -c "alpha beta" -h "gamma"
==Notes==
This class inherits functionality for dealing with command line arguments from class ARGUMENTS
. It uses the feature separate_character_option_value
to return the values by option name for each of the two arguments. ARGUMENTS
provides a rich set of features for command line argument processing.
The simple version in [[#Solution|Solution]] below is as submitted to Rosetta Code to illustrate class ARGUMENTS
, but it should be noted that separate_character_option_value
is of a detached type and will return a void reference if no value is found for a specified character option. Therefore, a safer version of the use of separate_character_option_value
would include object test on the result:
if attached separate_character_option_value ('c') as l_val then
print ("Command line argument value for option 'c' is: ")
print (l_val + "%N")
end
if attached separate_character_option_value ('h') as l_val then
print ("Command line argument value for option 'h' is: ")
print (l_val + "%N")
end
==Source==
Problem description from [http://rosettacode.org/wiki/Command-line_arguments Rosetta Code]
==Solution==
class
APPLICATION
inherit
ARGUMENTS
create
make
feature {NONE} -- Initialization
make
-- Print values for arguments with options 'c' and 'h'.
do
print ("Command line argument value for option 'c' is: ")
print (separate_character_option_value ('c') + "%N")
print ("Command line argument value for option 'h' is: ")
print (separate_character_option_value ('h') + "%N")
io.read_line -- Keep console window open
end
end
==Output (for command line arguments: -c "alpha beta" -h "gamma")==
Command line argument value for option 'c' is: alpha beta
Command line argument value for option 'h' is: gamma
{{SeeAlso|[[Execution_profiles|How to run with arguments]]}}