Class: Luban::CLI::Command
Constant Summary
Constants inherited from Base
Base::DefaultSummaryIndent, Base::DefaultSummaryWidth, Base::DefaultTitleIndent
Instance Attribute Summary collapse
-
#command_chain ⇒ Object
readonly
Returns the value of attribute command_chain.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Base
#arguments, #commands, #default_argv, #description, #options, #parent, #prefix, #program_name, #result, #summary, #summary_indent, #summary_width, #title_indent, #version
Instance Method Summary collapse
- #action_method ⇒ Object
- #command(cmd, **opts, &blk) ⇒ Object
- #default_prefix ⇒ Object
-
#initialize(parent, name, command_chain: [name], **opts, &config_blk) ⇒ Command
constructor
A new instance of Command.
Methods inherited from Base
#action, #action!, #alter, #argument, configure, #default_program_name, #desc, #has_command?, #has_commands?, #help, #help_command, inherited, #list_commands, #long_desc, #option, #parse, #parse!, #parser, #program, #reset, #show_help, #show_help_for_command, #show_version, #switch, #task, #undef_command, #use_commands
Constructor Details
#initialize(parent, name, command_chain: [name], **opts, &config_blk) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 |
# File 'lib/luban/cli/command.rb', line 7 def initialize(parent, name, command_chain: [name], **opts, &config_blk) @name = name @command_chain = command_chain super(parent, name, **opts, &config_blk) end |
Instance Attribute Details
#command_chain ⇒ Object (readonly)
Returns the value of attribute command_chain.
5 6 7 |
# File 'lib/luban/cli/command.rb', line 5 def command_chain @command_chain end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/luban/cli/command.rb', line 4 def name @name end |
Instance Method Details
#action_method ⇒ Object
15 16 17 |
# File 'lib/luban/cli/command.rb', line 15 def action_method @action_method ||= "#{@prefix}#{command_chain.map(&:to_s).join('_').gsub(':', '_')}" end |
#command(cmd, **opts, &blk) ⇒ Object
19 20 21 22 |
# File 'lib/luban/cli/command.rb', line 19 def command(cmd, **opts, &blk) opts[:command_chain] = self.command_chain.clone.push(cmd) super end |
#default_prefix ⇒ Object
13 |
# File 'lib/luban/cli/command.rb', line 13 def default_prefix; '__command_'; end |