Added safer version in Notes.

Author:halw
Date:2010-04-21T13:43:34.000000Z


git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@566 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
halw
2010-04-21 13:43:34 +00:00
parent 1424bb8389
commit 414856a5e2

View File

@@ -14,6 +14,19 @@ myprogram -c "alpha beta" -h "gamma"
This class inherits functionality for dealing with command line arguments from class <code lang="eiffel">ARGUMENTS</code>. It uses the feature <code lang="eiffel">separate_character_option_value</code> to return the values by option name for each of the two arguments. <code lang="eiffel">ARGUMENTS</code> 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 <code lang="eiffel">ARGUMENTS</code>, but it should be noted that <code lang="eiffel">separate_character_option_value</code> 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 <code lang="eiffel">separate_character_option_value</code> would include object test on the result:
<code>
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
</code>
==Source==
Problem description from [http://rosettacode.org/wiki/Command-line_arguments Rosetta Code]