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
-
#parent ⇒ Object
The parent of this command, either the GLI app, or another command.
Instance Method Summary collapse
- #arg_name(d, options = []) ⇒ Object
-
#arguments_description ⇒ Object
Return the arguments description.
- #arguments_options ⇒ Object
-
#commands ⇒ Object
:nodoc:.
- #context_description ⇒ Object
- #default_description ⇒ Object
- #default_value(d) ⇒ Object
- #desc(d) ⇒ Object
-
#execute(global_options, options, arguments) ⇒ Object
Executes the command.
- #flag(*names) ⇒ Object
-
#flags ⇒ Object
Return the flags as a Hash.
- #get_default_command ⇒ Object
- #has_action? ⇒ Boolean
- #long_desc(d) ⇒ Object
-
#names ⇒ Object
Return the Array of the command’s names.
-
#nodoc ⇒ Object
Return true to avoid including this command in your help strings.
-
#skips_around ⇒ Object
If true, this command doesn’t want the around block called.
-
#skips_post ⇒ Object
If true, this command doesn’t want the post block run before it executes.
-
#skips_pre ⇒ Object
If true, this command doesn’t want the pre block run before it executes.
- #switch(*names) ⇒ Object
-
#switches ⇒ Object
Return the switches as a Hash.
- #topmost_ancestor ⇒ Object
-
#usage ⇒ Object
Get the usage string CR: This should probably not be here.
Instance Attribute Details
#parent ⇒ Object
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
83 84 85 86 87 88 89 |
# File 'lib/gli/command_support.rb', line 83 def arg_name(d,=[]) if parent.kind_of? Command parent.arg_name(d,) else super(d,) end end |
#arguments_description ⇒ Object
Return the arguments description
19 20 21 |
# File 'lib/gli/command_support.rb', line 19 def arguments_description @arguments_description end |
#arguments_options ⇒ Object
23 24 25 |
# File 'lib/gli/command_support.rb', line 23 def @arguments_options end |
#commands ⇒ Object
:nodoc:
117 118 119 |
# File 'lib/gli/command_support.rb', line 117 def commands # :nodoc: @commands ||= {} end |
#context_description ⇒ Object
9 10 11 |
# File 'lib/gli/command_support.rb', line 9 def context_description "in the command #{name}" end |
#default_description ⇒ Object
121 122 123 |
# File 'lib/gli/command_support.rb', line 121 def default_description @default_desc end |
#default_value(d) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/gli/command_support.rb', line 91 def default_value(d) if parent.kind_of? Command parent.default_value(d) else super(d) end end |
#desc(d) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/gli/command_support.rb', line 67 def desc(d) if parent.kind_of? Command parent.desc(d) else super(d) end end |
#execute(global_options, options, arguments) ⇒ Object
Executes the command
126 127 128 129 130 131 132 133 |
# File 'lib/gli/command_support.rb', line 126 def execute(,,arguments) subcommand,arguments = find_subcommand(arguments) if subcommand subcommand.execute(,,arguments) else get_action(arguments).call(,,arguments) end end |
#flag(*names) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/gli/command_support.rb', line 47 def flag(*names) new_flag = if parent.kind_of? Command parent.flag(*names) else super(*names) end new_flag.associated_command = self new_flag end |
#flags ⇒ Object
Return the flags as a Hash
109 110 111 |
# File 'lib/gli/command_support.rb', line 109 def flags @flags ||= {} end |
#get_default_command ⇒ Object
149 150 151 |
# File 'lib/gli/command_support.rb', line 149 def get_default_command @default_command end |
#has_action? ⇒ Boolean
145 146 147 |
# File 'lib/gli/command_support.rb', line 145 def has_action? !!@action end |
#long_desc(d) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/gli/command_support.rb', line 75 def long_desc(d) if parent.kind_of? Command parent.long_desc(d) else super(d) end end |
#names ⇒ Object
Return the Array of the command’s names
43 44 45 |
# File 'lib/gli/command_support.rb', line 43 def names all_forms end |
#nodoc ⇒ Object
Return true to avoid including this command in your help strings
14 15 16 |
# File 'lib/gli/command_support.rb', line 14 def nodoc false end |
#skips_around ⇒ Object
If true, this command doesn’t want the around block called
38 39 40 |
# File 'lib/gli/command_support.rb', line 38 def skips_around @skips_around end |
#skips_post ⇒ Object
If true, this command doesn’t want the post block run before it executes
33 34 35 |
# File 'lib/gli/command_support.rb', line 33 def skips_post @skips_post end |
#skips_pre ⇒ Object
If true, this command doesn’t want the pre block run before it executes
28 29 30 |
# File 'lib/gli/command_support.rb', line 28 def skips_pre @skips_pre end |
#switch(*names) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/gli/command_support.rb', line 57 def switch(*names) new_switch = if parent.kind_of? Command parent.switch(*names) else super(*names) end new_switch.associated_command = self new_switch end |
#switches ⇒ Object
Return the switches as a Hash
113 114 115 |
# File 'lib/gli/command_support.rb', line 113 def switches @switches ||= {} end |
#topmost_ancestor ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/gli/command_support.rb', line 135 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 |
#usage ⇒ Object
Get the usage string CR: This should probably not be here
101 102 103 104 105 106 |
# File 'lib/gli/command_support.rb', line 101 def usage usage = name.to_s usage += ' [command options]' if !flags.empty? || !switches.empty? usage += ' ' + @arguments_description if @arguments_description usage end |