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
-
#commands ⇒ HashWithIndifferentAccess
readonly
Returns the list of subcommands of this command.
-
#options ⇒ HashWithIndifferentAccess
readonly
Returns the list of options of this command.
Instance Method Summary collapse
-
#argument(value) ⇒ Object
Adds a new argument to this command.
-
#arguments ⇒ Array
Returns the list of arguments of this command.
-
#clear_commands ⇒ Hash
Clear all subcommands of this commands.
-
#clear_options ⇒ Hash
Clear all the options of this commands.
-
#command(name, options = {}, &block) ⇒ Command
Adds a new subcommand to this command.
-
#get_options(unprovided = false, application = "application_", prefix = "", *whitelist) ⇒ HashWithIndifferentAccess
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.
-
#has_commands? ⇒ Boolean
Check if this command has subcommands.
-
#has_options? ⇒ Boolean
Check if this command has options.
-
#option(name, forms = [], options = {}, &action) ⇒ Option
Adds a new option to this command.
Instance Attribute Details
#commands ⇒ HashWithIndifferentAccess (readonly)
Returns the list of subcommands of this command.
181 182 183 |
# File 'lib/bovem/command.rb', line 181 def commands @commands end |
#options ⇒ HashWithIndifferentAccess (readonly)
Returns the list of options of this command.
202 203 204 |
# File 'lib/bovem/command.rb', line 202 def @options end |
Instance Method Details
#argument(value) ⇒ Object
Adds a new argument to this command.
222 223 224 225 |
# File 'lib/bovem/command.rb', line 222 def argument(value) @args ||= [] @args << value end |
#arguments ⇒ Array
Returns the list of arguments of this command.
230 231 232 |
# File 'lib/bovem/command.rb', line 230 def arguments @args || [] end |
#clear_commands ⇒ Hash
Clear all subcommands of this commands.
188 189 190 |
# File 'lib/bovem/command.rb', line 188 def clear_commands @commands = {} end |
#clear_options ⇒ Hash
Clear all the options of this commands.
208 209 210 |
# File 'lib/bovem/command.rb', line 208 def @options = {} end |
#command(name, options = {}, &block) ⇒ Command
Adds a new subcommand to this command.
142 143 144 145 146 147 148 149 |
# File 'lib/bovem/command.rb', line 142 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 |
#get_options(unprovided = false, application = "application_", prefix = "", *whitelist) ⇒ HashWithIndifferentAccess
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.
244 245 246 247 248 249 |
# File 'lib/bovem/command.rb', line 244 def (unprovided = false, application = "application_", prefix = "", *whitelist) rv = HashWithIndifferentAccess.new rv.merge!(self.application.(unprovided, nil, application, *whitelist)) if application && !is_application? rv.merge!((unprovided, prefix, whitelist)) rv end |
#has_commands? ⇒ Boolean
Check if this command has subcommands.
195 196 197 |
# File 'lib/bovem/command.rb', line 195 def has_commands? commands.length > 0 end |
#has_options? ⇒ Boolean
Check if this command has options.
215 216 217 |
# File 'lib/bovem/command.rb', line 215 def .length > 0 end |
#option(name, forms = [], options = {}, &action) ⇒ Option
Adds a new option to this command.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/bovem/command.rb', line 160 def option(name, forms = [], = {}, &action) name = name.ensure_string @options ||= HashWithIndifferentAccess.new if @options[name] then if is_application? then raise Bovem::Errors::Error.new(self, :duplicate_option, i18n.existing_option_global(name)) else raise Bovem::Errors::Error.new(self, :duplicate_option, i18n.existing_option(name, full_name)) end end option = Bovem::Option.new(name, forms, , &action) option.parent = self @options[name] = option option end |