class OptionGrouper::Group

A Group contains some parameters

Attributes

opts[R]

@private

Public Class Methods

new(name) click to toggle source

Initialize a new group @param name [Symbol] name of the group

# File lib/optiongrouper.rb, line 15
def initialize name
  @name = name
  @long = name.to_s.gsub(/_/, '-')
  @opts = {}
end

Public Instance Methods

header(*args) click to toggle source

@overload header

Gets current header message.
@return [String] header message

@overload header str

Sets a new header message
@param str [String] new header message
@return [String] header message
# File lib/optiongrouper.rb, line 76
def header *args
  if args.size == 0
    if @header
      "#{@header} (#{@long}):"
    else
      "#{@long}:"
    end
  else
    @header = args[0]
  end
end
invoke(&blk) click to toggle source

Invoke Group in a block to configure

# File lib/optiongrouper.rb, line 22
def invoke &blk
  Blockenspiel.invoke blk, self
end
long(*args) click to toggle source

Defines the name used in command line. By default it’s the normal name with underscores replaced with hyphens. It’s not advised to change it. @overload long()

Gets current command line name.
@return [String] current name

@overload long str

Sets current command line name.
@return [String] the newly set name
# File lib/optiongrouper.rb, line 61
def long *args
  if args.size == 0
    @long
  else
    @long = args[0]
  end
end
opt(name, desc, opts = {}) click to toggle source

Define a new option @param name [Symbol] name of the parameter. Underscores will be converted

to hypens in long argument, and a short one will be generated unless you
define one or you declare not to generate one.

@param desc [#to_s] description of the argument. @param opts [Hash] additional options. @option opts [String] :long use this as a long option. @option opts [String] :short use this as a short option (must be 1

character long to work)

@option opts [Boolean] :no_short do not automatically generate a short

option if set to true

@option opts [Proc] :on invoke block after parsing argument @option opts [Symbol, Array<Symbol>, Array<Array<Symbol, String>>]

:value describe additional values to the argument. Symbols declare the
type of the value, and also the string displayed on help page using
`[[Symbol, String], ...]` syntax.

@option opts :default (nil) default value of the option if not specified

on command line.

@option opts :set (true) set valueless commands to this if specified. @return [void]

# File lib/optiongrouper.rb, line 46
def opt name, desc, opts = {}
  opts[:desc] = desc
  opts[:long] ||= name.to_s.gsub(/_/, '-')
  opts[:set] ||= true
  @opts[name] = opts
end