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

Treat the command line (including the arguments) as a source of choices.


Public Class methods

Public Instance methods

Add a single line composed of string to the current position in the help output.

Called in the case of command-line error or explicit request (—help) to print usage information.

The usage_lines will be used to produce the output from —help (or on error).

The single argument required argument is turned into a string indexed by choice. Any other case is an error.

Bundle up all non-option and non-switch arguments into an array of strings indexed by choice.

Describes how a particular choice is represented on the command line. The args are passed to OptionParser. Each arg will either describe one variant of option (such as "-s" or "—show VALUE") or is a line of help text about the option (multiple lines are allowed).

If the option takes an array of values, separate the values by commas: —files a,b,c There‘s currently no way to escape a comma and no cleverness about quotes.

If a single argument is present, it (as a string) is the value of choice. If no argument is present, choice has no value. Any other case is an error.

A switch is an option that doesn‘t take a value. A switch described as "—switch" has these effects:

  • If it is not given, the choice is the default value or is not present in the hash that holds all the choices.
  • If it is given as —switch, the choice has the value "true". (If the choice was described in ChoicesBuilder#add_choice as having a :type => :boolean, that value is converted from a string to true.)
  • If it is given as —no-switch, the choice has the value "false".