Class | Console::Arguments
In: | lib/facets/more/arguments.rb
Parent: | Object

# Console Arguments

Console Arguments provaide a simpel and convient measn of parsing arguments passed to via commandline.

Unlike other more complex libs (like Facets’ own Console::Command) Arguments provides only the basic standard parsing functionality. In many casses that‘s all one really needs.

### Methods

flags multi_command new parameters parse preflags preflags! words

### Attributes

argv | [R] |
arity | [R] |
line | [R] |
opts | [R] |

### Public Class methods

new( line=nil, *opts_arity )

### Public Instance methods

flags( *opts_arity )
multi_command(

Multi-command.

Parses a chain of commands from a single command line. This assumes commands take no free standing arguments, and rather only utilize option flags.

      line = "--trace rubyforge --groupid=2014 publish --copy='**/*'

This method does not support flag arity since each command in the chain could have it‘s own arity settings. So ’=’ must be used to set a flag parameter.

parameters()

Returns the parsed command line as an array + hash collection of parameters, like what a Ruby method accepts. Because of the use of the hash for flags and options parameters, repeat entries can be used with this, in that case use parse directly.

parse(

Basic parser partitions the command line into flags and arguments. Flags are converted to a associative array and then the two parts are returned.

      line = "--trace stamp --file=VERSION"

      args,keys = *parse_command(line)

      args #=> ["stamp"]
      keys #=> [["trace",true], ["file","VERSION"]]

preflags(

Parse off the front flags of a command line.

      line = "--trace stamp --file VERSION"

      argv,keys = *parse_front_flags(line)

      argv #=> ["stamp", "--file", "VERSION"]
      keys #=> [["trace", true]]

Provided an arity hash if any flags take free standing parameters.

      line = "--level 4 stamp --file VERSION"

      argv,keys = *parse_front_flags(line, :trace => 1)

      argv #=> ["stamp", "--file", "VERSION"]
      keys #=> [["level", 4]]

preflags!(

Like preflags but will remove preflags from the argumuments array (argv).

words( *opts_arity )

[Validate]