Class: BaseChip::Cli::Data
- Inherits:
-
TaskOrData
- Object
- TaskOrData
- BaseChip::Cli::Data
- Defined in:
- lib/base_chip/cli.rb
Instance Attribute Summary collapse
-
#current_task ⇒ Object
Returns the value of attribute current_task.
-
#default_task ⇒ Object
Returns the value of attribute default_task.
-
#map ⇒ Object
Returns the value of attribute map.
-
#parent_command ⇒ Object
Returns the value of attribute parent_command.
-
#sub_commands ⇒ Object
Returns the value of attribute sub_commands.
-
#tasks ⇒ Object
Returns the value of attribute tasks.
Attributes inherited from TaskOrData
#description, #long_description, #name, #options
Instance Method Summary collapse
- #full_command(task = nil, with_options = true) ⇒ Object
-
#initialize ⇒ Data
constructor
A new instance of Data.
- #save_task(name, prc) ⇒ Object
- #sub_command(name, klass) ⇒ Object
Methods inherited from TaskOrData
#mine_options, #option, #option_usage, #options_table, #s2o, #table
Methods included from Reporting
Constructor Details
#initialize ⇒ Data
Returns a new instance of Data.
209 210 211 212 213 214 215 216 |
# File 'lib/base_chip/cli.rb', line 209 def initialize super @map = {} @sub_commands = {} @tasks = {} @current_task = self @default_task = nil end |
Instance Attribute Details
#current_task ⇒ Object
Returns the value of attribute current_task.
203 204 205 |
# File 'lib/base_chip/cli.rb', line 203 def current_task @current_task end |
#default_task ⇒ Object
Returns the value of attribute default_task.
204 205 206 |
# File 'lib/base_chip/cli.rb', line 204 def default_task @default_task end |
#map ⇒ Object
Returns the value of attribute map.
202 203 204 |
# File 'lib/base_chip/cli.rb', line 202 def map @map end |
#parent_command ⇒ Object
Returns the value of attribute parent_command.
207 208 209 |
# File 'lib/base_chip/cli.rb', line 207 def parent_command @parent_command end |
#sub_commands ⇒ Object
Returns the value of attribute sub_commands.
208 209 210 |
# File 'lib/base_chip/cli.rb', line 208 def sub_commands @sub_commands end |
#tasks ⇒ Object
Returns the value of attribute tasks.
205 206 207 |
# File 'lib/base_chip/cli.rb', line 205 def tasks @tasks end |
Instance Method Details
#full_command(task = nil, with_options = true) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/base_chip/cli.rb', line 240 def full_command(task = nil, =true) task = task.to_s if task n = if self.parent_command self.parent_command.full_command((task.nil? ? nil : self.name),) else File.basename($0) end if task n + ' ' + task else n end end |
#save_task(name, prc) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/base_chip/cli.rb', line 217 def save_task(name,prc) return if self == @current_task @current_task.required_argument_size = 0 @current_task.usage ||= prc.parameters.map do |pa| case pa[0] when :req ; @current_task.required_argument_size += 1 ; "<#{pa[1]}>" when :opt ; "[#{pa[1]}]" when :rest ; "[#{pa[1]}]+" end end.join(' ') + ' [options]' @current_task.name = name @tasks[name] = @current_task @current_task = self end |
#sub_command(name, klass) ⇒ Object
232 233 234 235 236 237 238 239 |
# File 'lib/base_chip/cli.rb', line 232 def sub_command(name,klass) @sub_commands[name] = klass klass.cli.parent_command = self klass.cli.name = name klass.cli.description = @current_task.description klass.cli.long_description = @current_task.long_description @current_task = self end |