Module: GLI::CommandSupport

Included in:
Command
Defined in:
lib/gli/command_support.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject

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



7
8
9
# File 'lib/gli/command_support.rb', line 7

def parent
  @parent
end

Instance Method Details

#arg_name(d, options = []) ⇒ Object



93
94
95
96
# File 'lib/gli/command_support.rb', line 93

def arg_name(d,options=[])
  parent.arg_name(d,options) if parent.kind_of?(Command) && send_declarations_to_parent?
  super(d,options)
end

#arguments_descriptionObject

Return the arguments description



20
21
22
# File 'lib/gli/command_support.rb', line 20

def arguments_description 
  @arguments_description
end

#arguments_optionsObject



24
25
26
# File 'lib/gli/command_support.rb', line 24

def arguments_options
  @arguments_options
end

#commandsObject

:nodoc:



112
113
114
# File 'lib/gli/command_support.rb', line 112

def commands # :nodoc:
  @commands ||= {}
end

#commands_declaration_orderObject

Get an array of commands, ordered by when they were declared



49
50
51
# File 'lib/gli/command_support.rb', line 49

def commands_declaration_order # :nodoc:
  @commands_declaration_order
end

#context_descriptionObject



9
10
11
# File 'lib/gli/command_support.rb', line 9

def context_description
  "in the command #{name}"
end

#default_descriptionObject



116
117
118
# File 'lib/gli/command_support.rb', line 116

def default_description
  @default_desc
end

#default_value(d) ⇒ Object



98
99
100
101
# File 'lib/gli/command_support.rb', line 98

def default_value(d)
  parent.default_value(d) if parent.kind_of?(Command) && send_declarations_to_parent?
  super(d)
end

#desc(d) ⇒ Object



83
84
85
86
# File 'lib/gli/command_support.rb', line 83

def desc(d)
  parent.desc(d) if parent.kind_of?(Command) && send_declarations_to_parent?
  super(d)
end

#execute(global_options, options, arguments) ⇒ Object

Executes the command



121
122
123
# File 'lib/gli/command_support.rb', line 121

def execute(global_options,options,arguments) 
  get_action(arguments).call(global_options,options,arguments)
end

#flag(*names) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gli/command_support.rb', line 53

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

#flagsObject

Return the flags as a Hash



104
105
106
# File 'lib/gli/command_support.rb', line 104

def flags 
  @flags ||= {}
end

#get_default_commandObject



139
140
141
# File 'lib/gli/command_support.rb', line 139

def get_default_command
  @default_command
end

#has_action?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/gli/command_support.rb', line 135

def has_action?
  !!@action
end

#long_desc(d) ⇒ Object



88
89
90
91
# File 'lib/gli/command_support.rb', line 88

def long_desc(d)
  parent.long_desc(d) if parent.kind_of?(Command) && send_declarations_to_parent?
  super(d)
end

#namesObject

Return the Array of the command’s names



44
45
46
# File 'lib/gli/command_support.rb', line 44

def names 
  all_forms
end

#nodocObject

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



15
16
17
# File 'lib/gli/command_support.rb', line 15

def nodoc
  @hide_commands_without_desc and description.nil?
end

#skips_aroundObject

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



39
40
41
# File 'lib/gli/command_support.rb', line 39

def skips_around
  @skips_around
end

#skips_postObject

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



34
35
36
# File 'lib/gli/command_support.rb', line 34

def skips_post 
  @skips_post
end

#skips_preObject

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



29
30
31
# File 'lib/gli/command_support.rb', line 29

def skips_pre 
  @skips_pre
end

#switch(*names) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/gli/command_support.rb', line 68

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

#switchesObject

Return the switches as a Hash



108
109
110
# File 'lib/gli/command_support.rb', line 108

def switches 
  @switches ||= {}
end

#topmost_ancestorObject



125
126
127
128
129
130
131
132
133
# File 'lib/gli/command_support.rb', line 125

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