Module: Bovem::CommandMethods::Children
- Included in:
- Bovem::Command
- Defined in:
- lib/bovem/command.rb
Overview
Methods to manage options and subcommands.
Instance Attribute Summary (collapse)
-
- (HashWithIndifferentAccess) commands
readonly
Returns the list of subcommands of this command.
-
- (HashWithIndifferentAccess) options
readonly
Returns the list of options of this command.
Instance Method Summary (collapse)
-
- (Object) argument(value)
Adds a new argument to this command.
-
- (Array) arguments
Returns the list of arguments of this command.
-
- (Hash) clear_commands
Clear all subcommands of this commands.
-
- (Hash) clear_options
Clear all the options of this commands.
-
- (Command) command(name, options = {}, &block)
Adds a new subcommand to this command.
-
- (Boolean) commands?
Check if this command has subcommands.
-
- (HashWithIndifferentAccess) get_options(unprovided: false, application: "application_", prefix: "", whitelist: [])
Get the list of the options of this command as an hash, where the keys are the options and the values are either the user inputs or the defaults values.
-
- (Option) option(name, forms = [], options = {}, &action)
Adds a new option to this command.
-
- (Boolean) options?
Check if this command has options.
Instance Attribute Details
- (HashWithIndifferentAccess) commands (readonly)
Returns the list of subcommands of this command.
176 177 178 |
# File 'lib/bovem/command.rb', line 176 def commands @commands end |
- (HashWithIndifferentAccess) options (readonly)
Returns the list of options of this command.
197 198 199 |
# File 'lib/bovem/command.rb', line 197 def @options end |
Instance Method Details
- (Object) argument(value)
Adds a new argument to this command.
217 218 219 220 |
# File 'lib/bovem/command.rb', line 217 def argument(value) @args ||= [] @args << value end |
- (Array) arguments
Returns the list of arguments of this command.
225 226 227 |
# File 'lib/bovem/command.rb', line 225 def arguments @args || [] end |
- (Hash) clear_commands
Clear all subcommands of this commands.
183 184 185 |
# File 'lib/bovem/command.rb', line 183 def clear_commands @commands = {} end |
- (Hash) clear_options
Clear all the options of this commands.
203 204 205 |
# File 'lib/bovem/command.rb', line 203 def @options = {} end |
- (Command) command(name, options = {}, &block)
Adds a new subcommand to this command.
141 142 143 144 145 146 147 148 |
# File 'lib/bovem/command.rb', line 141 def command(name, = {}, &block) @commands ||= HashWithIndifferentAccess.new = {name: name.to_s, parent: self, application: application}.merge(.ensure_hash) raise Bovem::Errors::Error.new(self, :duplicate_command, i18n.existing_command(full_name(name))) if @commands[name.to_s] create_command(name, , &block) end |
- (Boolean) commands?
Check if this command has subcommands.
190 191 192 |
# File 'lib/bovem/command.rb', line 190 def commands? !commands.empty? end |
- (HashWithIndifferentAccess) get_options(unprovided: false, application: "application_", prefix: "", whitelist: [])
Get the list of the options of this command as an hash, where the keys are the options and the values are either the user inputs or the defaults values.
If the two prefixes collides, the command options take precedence over application options.
239 240 241 242 243 244 245 246 247 248 |
# File 'lib/bovem/command.rb', line 239 def (unprovided: false, application: "application_", prefix: "", whitelist: []) rv = HashWithIndifferentAccess.new if application && !application? rv.merge!(self.application.(unprovided: unprovided, application: nil, prefix: application, whitelist: whitelist)) end rv.merge!((unprovided, prefix, whitelist)) rv end |
- (Option) option(name, forms = [], options = {}, &action)
Adds a new option to this command.
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/bovem/command.rb', line 159 def option(name, forms = [], = {}, &action) name = name.ensure_string @options ||= HashWithIndifferentAccess.new if @options[name] raise Bovem::Errors::Error.new(self, :duplicate_option, application? ? i18n.existing_option_global(name) : i18n.existing_option(name, full_name)) end option = Bovem::Option.new(name, forms, , &action) option.parent = self @options[name] = option option end |
- (Boolean) options?
Check if this command has options.
210 211 212 |
# File 'lib/bovem/command.rb', line 210 def !.empty? end |