Class: Brigadier::Commands::SubCommand

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/brigadier/commands/sub_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#assign_arguments_from, #assign_options_from, #assign_toggles_from, #create_variable_and_method_from, #ensure_parameters_defined!, #hidden?, #process_args

Methods included from Helper

#available_params_for, #display_help_for, #display_help_if_requested, #help, #help_requested?, #inverse_toggle_arg?, #option_or_toggle?

Constructor Details

#initialize(name, description, instance, args, block) ⇒ SubCommand

Returns a new instance of SubCommand.



8
9
10
11
12
13
14
# File 'lib/brigadier/commands/sub_command.rb', line 8

def initialize(name, description, instance, args, block)
  @name = name
  @description = description
  @instance = instance
  @args = args
  @block = block
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/brigadier/commands/sub_command.rb', line 6

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/brigadier/commands/sub_command.rb', line 6

def name
  @name
end

Instance Method Details

#display_descriptionObject



20
21
22
# File 'lib/brigadier/commands/sub_command.rb', line 20

def display_description
  description
end

#display_nameObject



16
17
18
# File 'lib/brigadier/commands/sub_command.rb', line 16

def display_name
  aliases.join(', ')
end

#execute(args, full_args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/brigadier/commands/sub_command.rb', line 24

def execute(args, full_args)
  block.call

  process_args(args.dup, klass)

  assign_toggles_from(available_toggles)
  assign_options_from(available_options)
  assign_arguments_from(available_arguments)

  return if display_help_if_requested(klass, full_args)

  ensure_parameters_defined!(available_options, available_arguments)

  if (execute = klass.instance_variable_get('@execute_proc'))
    instance.instance_eval(&execute)
  else
    raise Exceptions::ExecuteBlockMissing.new(self), 'There is no execute {} block defined'
  end
end

#sub_command?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/brigadier/commands/sub_command.rb', line 44

def sub_command?
  true
end