Class: Luban::CLI::Command

Inherits:
Base
  • Object
show all
Defined in:
lib/luban/cli/command.rb

Constant Summary

Constants inherited from Base

Base::DefaultSummaryIndent, Base::DefaultSummaryWidth, Base::DefaultTitleIndent

Instance Attribute Summary collapse

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

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_chainObject (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

#nameObject (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_methodObject



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_prefixObject



13
# File 'lib/luban/cli/command.rb', line 13

def default_prefix; '__command_'; end