Class UserChoices::PosixCommandLineSource
In: lib/user-choices/command-line-source.rb
Parent: CommandLineSource

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.



Public Instance methods