mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-08 07:42:33 +01:00
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:
@@ -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.
|
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==
|
==Source==
|
||||||
|
|
||||||
Problem description from [http://rosettacode.org/wiki/Command-line_arguments Rosetta Code]
|
Problem description from [http://rosettacode.org/wiki/Command-line_arguments Rosetta Code]
|
||||||
|
|||||||
Reference in New Issue
Block a user