Class | Argvector |
In: |
lib/more/facets/argvector.rb
|
Parent: | Object |
Argvector provides a very simple means of parsing command line arguments.
Unlike other more complex libs this provides only the most basic and standard parsing functionality. In many cases that‘s all one really needs.
Usage is straight foward. Simply instantiate the class and query it for the particular "views" of the command line you want.
cargs = Argvector.new("-a foo -b=2") cargs.parameters #=> [['foo'],{'a'=>true,'b'=>'2'}] cargs.flags #=> ['a'] cargs.preoptions #=> {'a'=>true} cargs.preflags #=> ['a'] cargs.subcommand #=> ['foo', [], {'b'=>'2'}]
argv | [R] | |
arity | [R] | |
line | [R] |
Split single letter option groupings into separate options. ie. -xyz => -x -y -z
First pass parser to split the command line into an array using Shellwords, if not already so divided.
Parse preoptions. A "preoption" is one that occurs before the first operans (if any).
Returns a hash of options that occur before the first operand. This works well with subcommand to get the main command‘s options.
line = "--trace stamp --file VERSION" cargs = Argvector.new(line) opts = cargs.preoptions opts #=> {"trace"=>true}
Assumes the first operand is a "subcommand" and returns it and the argments following it as another Arguments object.
TODO: This probably should be called ‘subcommand’.
Assumes the first operand is a "subcommand" and returns it and the argments following it as parameters.