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.
# 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