Class: QB::Options
- Inherits:
-
Object
- Object
- QB::Options
- Includes:
- NRSER::Log::Mixin
- Defined in:
- lib/qb/options.rb,
lib/qb/options/types.rb,
lib/qb/options/option.rb,
lib/qb/options/option/option_parser_concern.rb
Defined Under Namespace
Modules: Types Classes: Option
Constant Summary collapse
- QB_DEFAULTS =
Default initial values for #qb.
{ 'hosts' => ['localhost'].freeze, 'facts' => true, 'print' => [].freeze, 'verbose' => false, 'run' => true, 'ask' => false, }.freeze
- SPACER =
Appended on the end of an
opts.on
call to create a newline after the option (making the help output a bit easier to read)You might think the empty string would be reasonable, but OptionParser blows up if you do that.
' '
Instance Attribute Summary collapse
-
#ansible ⇒ Object
readonly
Returns the value of attribute ansible.
-
#qb ⇒ Object
readonly
Returns the value of attribute qb.
-
#role_options ⇒ Object
readonly
Returns the value of attribute role_options.
Class Method Summary collapse
-
.add(opts, options, role, include_path = []) ⇒ Object
Add the options from a role to the OptionParser.
-
.cli_ize_name(option_name) ⇒ String
turn a name into a "command line" version by replacing underscores with dashes.
- .include_role(opts, options, include_meta, include_path) ⇒ Object
-
.parse!(role, argv) ⇒ Array<Hash<String, Option|Object>>
Destructively removes options from
@argv
and populates ansible, role, and qb option hashes. -
.var_ize_name(option_name) ⇒ String
turn a name into a "ruby / ansible variable" version by replacing dashes with underscores.
Instance Method Summary collapse
- #ask? ⇒ return_type
-
#initialize(role, argv) ⇒ Options
constructor
A new instance of Options.
Constructor Details
#initialize(role, argv) ⇒ Options
Returns a new instance of Options.
187 188 189 190 191 192 193 |
# File 'lib/qb/options.rb', line 187 def initialize role, argv @role = role @argv = argv @qb = QB_DEFAULTS.dup parse! end |
Instance Attribute Details
#ansible ⇒ Object (readonly)
Returns the value of attribute ansible.
59 60 61 |
# File 'lib/qb/options.rb', line 59 def ansible @ansible end |
#qb ⇒ Object (readonly)
Returns the value of attribute qb.
69 70 71 |
# File 'lib/qb/options.rb', line 69 def qb @qb end |
#role_options ⇒ Object (readonly)
Returns the value of attribute role_options.
64 65 66 |
# File 'lib/qb/options.rb', line 64 def @role_options end |
Class Method Details
.add(opts, options, role, include_path = []) ⇒ Object
Add the options from a role to the OptionParser
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/qb/options.rb', line 137 def self.add opts, , role, include_path = [] QB.debug "adding options", "role" => role role..each do || if .key? 'include' include_role opts, , , include_path else # create an option option = Option.new role, , include_path option.option_parser_add opts, included: !include_path.empty? [option.cli_name] = option end end # each var end |
.cli_ize_name(option_name) ⇒ String
turn a name into a "command line" version by replacing underscores with dashes.
86 87 88 |
# File 'lib/qb/options.rb', line 86 def self.cli_ize_name option_name option_name.gsub '_', '-' end |
.include_role(opts, options, include_meta, include_path) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/qb/options.rb', line 106 def self.include_role opts, , , include_path role_name = ['include'] role = QB::Role.require role_name new_include_path = if .key? 'as' case ['as'] when nil, false # include it in with the parent role's options include_path when String include_path + [['as']] else raise QB::Role::MetadataError.new, "bad 'as' value: #{ .inspect }" end else include_path + [role.namespaceless] end QB.debug "including #{ role.name } as #{ new_include_path.join('-') }" opts.separator "Options for included #{ role.name } role:" add opts, , role, new_include_path end |
.parse!(role, argv) ⇒ Array<Hash<String, Option|Object>>
Destructively removes options from @argv
and populates ansible, role,
and qb option hashes.
175 176 177 178 |
# File 'lib/qb/options.rb', line 175 def self.parse! role, argv = self.new role, argv [., .qb] end |
.var_ize_name(option_name) ⇒ String
turn a name into a "ruby / ansible variable" version by replacing dashes with underscores.
102 103 104 |
# File 'lib/qb/options.rb', line 102 def self.var_ize_name option_name option_name.gsub '-', '_' end |
Instance Method Details
#ask? ⇒ return_type
Document ask? method.
Returns @todo Document return value.
204 205 206 |
# File 'lib/qb/options.rb', line 204 def ask? @qb['ask'] end |