class Commander

Commands/Commander registry

Public Class Methods

commands() click to toggle source
# File lib/commands-lite/base.rb, line 90
def self.commands  ## todo/check: change to registry or such - why? why not?
  @@register ||= {}
end
register( klass ) click to toggle source
# File lib/commands-lite/base.rb, line 94
def self.register( klass )
  raise ArgumentError, "class MUST be a Command"   unless klass.ancestors.include?( Command )

  h = commands
  h[ klass.command_name] = klass
  h
end
run( args=[] ) click to toggle source
# File lib/commands-lite/base.rb, line 103
def self.run( args=[] )
  command_name = args.shift

  ## 1) downcase  e.g. GithubStats
  ## 2) remove - to _   ## treat them the same e.g. github-stats => github_stats
  command_name = command_name
                   .gsub( /[_-]/, '' )
                   .downcase

  command = commands[ command_name ]
  if command.nil?
    puts "!! ERROR: no command definition found for >#{command_name}<; known commands include:"
    pp commands
    exit 1
  end

  command.run( args )
end