Class: UserChoices::PosixCommandLineSource
- Inherits:
-
CommandLineSource
- Object
- Hash
- AbstractSource
- CommandLineSource
- UserChoices::PosixCommandLineSource
- Defined in:
- lib/user-choices/command-line-source.rb
Overview
Process command-line choices according to POSIX rules. Consider
ruby copy.rb file1 –odd-file-name
Ordinarily, that’s permuted so that –odd-file-name is expected to be an option or switch, not an argument. One way to make CommandLineSource parsing treat it as an argument is to use a – to signal the end of option parsing:
ruby copy.rb – file1 –odd-file-name
Another is to rely on the user to set environment variable POSIXLY_CORRECT.
Since both of those require the user to do something, they’re error-prone.
Another way is to use this class, which obeys POSIX-standard rules. Under those rules, the first word on the command line that does not begin with a dash marks the end of all options. In that case, the first command line above would parse into two arguments and no options.
Instance Attribute Summary
Attributes inherited from AbstractSource
Instance Method Summary collapse
Methods inherited from CommandLineSource
#add_help_line, #adjust, #apply, #deep_copy, #exit_upon_error, #help, #help_banner, #initialize, #source, #usage, #use_strategy, #uses_arg, #uses_arglist, #uses_option, #uses_optional_arg, #uses_switch
Methods inherited from AbstractSource
#adjust, #apply, #each_conversion, #initialize, #source
Constructor Details
This class inherits a constructor from UserChoices::CommandLineSource
Instance Method Details
#fill ⇒ Object
211 212 213 214 215 216 217 218 219 |
# File 'lib/user-choices/command-line-source.rb', line 211 def fill begin already_set = ENV.include?('POSIXLY_CORRECT') ENV['POSIXLY_CORRECT'] = 'true' unless already_set super ensure ENV.delete('POSIXLY_CORRECT') unless already_set end end |