Module: Mixlib::CLI::ClassMethods

Defined in:
lib/mixlib/cli.rb

Instance Method Summary collapse

Instance Method Details

Change the banner. Defaults to:

Usage: #{0} (options)

Parameters

bstring<String>

The string to set the banner to

Returns

@banner<String>

The current banner



66
67
68
69
70
71
72
73
# File 'lib/mixlib/cli.rb', line 66

def banner(bstring=nil)
  if bstring
    @banner = bstring
  else
    @banner ||= "Usage: #{$0} (options)"
    @banner
  end
end

#option(name, args) ⇒ Object

Add a command line option.

Parameters

name<Symbol>

The name of the option to add

args<Hash>

A hash of arguments for the option, specifying how it should be parsed.

Returns

true

Always returns true.

Raises:

  • (ArgumentError)


31
32
33
34
35
# File 'lib/mixlib/cli.rb', line 31

def option(name, args)
  @options ||= {}
  raise(ArgumentError, "Option name must be a symbol") unless name.kind_of?(Symbol)
  @options[name.to_sym] = args
end

#optionsObject

Get the hash of current options.

Returns

@options<Hash>

The current options hash.



41
42
43
44
# File 'lib/mixlib/cli.rb', line 41

def options
  @options ||= {}
  @options
end

#options=(val) ⇒ Object

Set the current options hash

Parameters

val<Hash>

The hash to set the options to

Returns

@options<Hash>

The current options hash.

Raises:

  • (ArgumentError)


53
54
55
56
# File 'lib/mixlib/cli.rb', line 53

def options=(val)
  raise(ArgumentError, "Options must recieve a hash") unless val.kind_of?(Hash)
  @options = val
end