Class: SCParse::HelpCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/scparse.rb

Overview

Special custom command for displaying help messages.

Instance Attribute Summary

Attributes inherited from Command

#commands, #name, #options, #parent

Instance Method Summary collapse

Methods inherited from Command

#add_command, #execute_prerequisites?, #has_command?, #has_commands?, #parents, #prerequisites, #scparser, #set_execution_block, #set_prerequisites_block, #usage

Constructor Details

#initializeHelpCommand

Returns a new instance of HelpCommand.



215
216
217
# File 'lib/scparse.rb', line 215

def initialize
  super('help')
end

Instance Method Details

#execute(args) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/scparse.rb', line 219

def execute(args)
  super(args)

  if args.length > 0
    cmd = scparser.main
    arg = args.shift

    while !arg.nil? && cmd.commands[arg]
      cmd = cmd.commands[arg]
      arg = args.shift
    end
    
    if arg.nil?
      cmd.show_help
    else
      puts "Command not valid"
    end
  else
    show_help
  end
end