module GLI::CommandSupport

Things unrelated to the true public interface of Command that are needed for bookkeeping and help support. Generally, you shouldn't be calling these methods; they are technically public but are essentially part of GLI's internal implementation and subject to change

Attributes

parent[RW]

The parent of this command, either the GLI app, or another command

Public Instance Methods

arg_name(d,options=[]) click to toggle source
Calls superclass method
# File lib/gli/command_support.rb, line 102
def arg_name(d,options=[])
  parent.arg_name(d,options) if parent.kind_of?(Command) && send_declarations_to_parent?
  super(d,options)
end
arguments() click to toggle source
# File lib/gli/command_support.rb, line 28
def arguments
  @arguments
end
arguments_description() click to toggle source

Return the arguments description

# File lib/gli/command_support.rb, line 20
def arguments_description 
  @arguments_description
end
arguments_options() click to toggle source
# File lib/gli/command_support.rb, line 24
def arguments_options
  @arguments_options
end
context_description() click to toggle source
# File lib/gli/command_support.rb, line 9
def context_description
  "in the command #{name}"
end
default_description() click to toggle source
# File lib/gli/command_support.rb, line 125
def default_description
  @default_desc
end
default_value(d) click to toggle source
Calls superclass method
# File lib/gli/command_support.rb, line 107
def default_value(d)
  parent.default_value(d) if parent.kind_of?(Command) && send_declarations_to_parent?
  super(d)
end
desc(d) click to toggle source
Calls superclass method
# File lib/gli/command_support.rb, line 92
def desc(d)
  parent.desc(d) if parent.kind_of?(Command) && send_declarations_to_parent?
  super(d)
end
examples() click to toggle source

Returns the array of examples

# File lib/gli/command_support.rb, line 53
def examples
  @examples
end
execute(global_options,options,arguments) click to toggle source

Executes the command

# File lib/gli/command_support.rb, line 130
def execute(global_options,options,arguments) 
  get_action(arguments).call(global_options,options,arguments)
end
flag(*names) click to toggle source
Calls superclass method
# File lib/gli/command_support.rb, line 62
def flag(*names)
  if send_declarations_to_parent?
    new_flag = if parent.kind_of? Command
                 super(*names)
                 parent.flag(*names)
               else
                 super(*names)
               end
    new_flag.associated_command = self
    new_flag
  else
    super(*names)
  end
end
flags() click to toggle source

Return the flags as a Hash

# File lib/gli/command_support.rb, line 113
def flags 
  @flags ||= {}
end
get_default_command() click to toggle source
# File lib/gli/command_support.rb, line 148
def get_default_command
  @default_command
end
has_action?() click to toggle source
# File lib/gli/command_support.rb, line 144
def has_action?
  !!@action
end
long_desc(d) click to toggle source
Calls superclass method
# File lib/gli/command_support.rb, line 97
def long_desc(d)
  parent.long_desc(d) if parent.kind_of?(Command) && send_declarations_to_parent?
  super(d)
end
names() click to toggle source

Return the Array of the command's names

# File lib/gli/command_support.rb, line 48
def names 
  all_forms
end
nodoc() click to toggle source

Return true to avoid including this command in your help strings Will honor the hide_commands_without_desc flag

# File lib/gli/command_support.rb, line 15
def nodoc
  @hide_commands_without_desc and description.nil?
end
skips_around() click to toggle source

If true, this command doesn't want the around block called

# File lib/gli/command_support.rb, line 43
def skips_around
  @skips_around
end
skips_post() click to toggle source

If true, this command doesn't want the post block run before it executes

# File lib/gli/command_support.rb, line 38
def skips_post 
  @skips_post
end
skips_pre() click to toggle source

If true, this command doesn't want the pre block run before it executes

# File lib/gli/command_support.rb, line 33
def skips_pre 
  @skips_pre
end
switch(*names) click to toggle source
Calls superclass method
# File lib/gli/command_support.rb, line 77
def switch(*names)
  if send_declarations_to_parent?
    new_switch = if parent.kind_of? Command
                   super(*names)
                   parent.switch(*names)
                 else
                   super(*names)
                 end
    new_switch.associated_command = self
    new_switch
  else
    super(*names)
  end
end
switches() click to toggle source

Return the switches as a Hash

# File lib/gli/command_support.rb, line 117
def switches 
  @switches ||= {}
end
topmost_ancestor() click to toggle source
# File lib/gli/command_support.rb, line 134
def topmost_ancestor
  some_command = self
  top = some_command
  while some_command.kind_of? self.class
    top = some_command
    some_command = some_command.parent
  end
  top
end

Private Instance Methods

am_subcommand?() click to toggle source
# File lib/gli/command_support.rb, line 183
def am_subcommand?
  parent.kind_of?(Command)
end
generate_error_action(arguments) click to toggle source
# File lib/gli/command_support.rb, line 167
def generate_error_action(arguments)
  lambda { |global_options,options,arguments|
    if am_subcommand?
      if arguments.size > 0
        raise UnknownCommand,"Unknown command '#{arguments[0]}'"
      else
        raise BadCommandLine,"Command '#{name}' requires a subcommand"
      end
    elsif have_subcommands?
      raise BadCommandLine,"Command '#{name}' requires a subcommand #{self.commands.keys.join(',')}"
    else
      raise "Command '#{name}' has no action block"
    end
  }
end
get_action(arguments) click to toggle source
# File lib/gli/command_support.rb, line 159
def get_action(arguments)
  if @action
    @action
  else
    generate_error_action(arguments)
  end
end
have_subcommands?() click to toggle source
# File lib/gli/command_support.rb, line 187
def have_subcommands?
  !self.commands.empty?
end
send_declarations_to_parent?() click to toggle source
# File lib/gli/command_support.rb, line 154
def send_declarations_to_parent?
  app = topmost_ancestor.parent
  app.nil? ? true : (app.subcommand_option_handling_strategy == :legacy)
end