Magni

Magni is a command line flag parser, nothing more, nothing less. It’s useful for when you want to collect a bunch of flags from your script, then do something with them all.

=== ARGUMENT TYPES

Magni accepts four types of arguments, boolean, string, array and integer.

boolean:   --foo          #=> true
integer:   --foo=4        #=> 4
 string:   --foo=theory   #=> "theory"
  array:   --foo=1,2,3    #=> [1, 2, 3]

MAPPINGS

Magni is the son of Thor and so he inherited some of his father’s traits; mapping being one of them.

class Runner < Magni
  map "--maxerr" => :integer
  map "--name"   => :string
  map "--help"   => :boolean
end

There are a couple special keywords that work with mappings too, :first and :last. Each one will place the first or last, respectively, argument in an instance variable for you. This is useful when the last argument of your script is a file or command for example.

map :last => :file

> script --hello world.rb
@file #=> "world.rb"

BIN SCRIPT

Tell Magni where to go after it does it’s flag parsing magic. delegate_to takes two arguments. The first is your Magni subclass and the second is the method you want to be called when Magni is done:

Magni.delegate_to(Runner, :method)

USING THE FLAGS

Flags and values are saved in @options. From the example above:

> script --maxerr=4 --name=Matte
@options #=> { :maxerr => 4, :name => "Matte" }

License

(The MIT License)

Copyright (c) 2010 FIXME full name

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.