Class MCollective::Optionparser
In: lib/mcollective/optionparser.rb
Parent: Object

A simple helper to build cli tools that supports a uniform command line layout.

Methods

Attributes

parser  [R] 

Public Class methods

Creates a new instance of the parser, you can supply defaults and include named groups of options.

Starts a parser that defaults to verbose and that includs the filter options:

 oparser = MCollective::Optionparser.new({:verbose => true}, "filter")

Stats a parser in non verbose mode that does support discovery

 oparser = MCollective::Optionparser.new()

Starts a parser in verbose mode that does not show the common options:

 oparser = MCollective::Optionparser.new({:verbose => true}, "filter", "common")

Public Instance methods

These options will be added to most cli tools

These options will be added if you pass ‘filter’ into the include list of the constructor.

These options should always be present

Parse the options returning the options, you can pass a block that adds additional options to the Optionparser.

The sample below starts a parser that also prompts for —arguments in addition to the defaults. It also sets the description and shows a usage message specific to this app.

 options = oparser.parse{|parser, options|
      parser.define_head "Control the mcollective controller daemon"
      parser.banner = "Usage: sh-mcollective [options] command"

      parser.on('--arg', '--argument ARGUMENT', 'Argument to pass to agent') do |v|
          options[:argument] = v
      end
 }

Users can set default options that get parsed in using the MCOLLECTIVE_EXTRA_OPTS environemnt variable

[Validate]