Class: Scm::Workflow::Utils::CommandDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/command-dispatcher.rb

Overview



Constant Summary collapse

EX_NOCMD =
"No command specified"
EX_INVALCMD =
"is not a valid command"

Instance Method Summary collapse

Constructor Details

#initialize(rootScriptAbsLocation, rootScriptName) ⇒ CommandDispatcher





19
20
21
22
23
# File 'lib/utils/command-dispatcher.rb', line 19

def initialize(rootScriptAbsLocation, rootScriptName)
  @rootScriptAbsLocation = rootScriptAbsLocation
  @rootScriptName = rootScriptName
  @commandPrefix = rootScriptAbsLocation + '/' + rootScriptName + '-';
end

Instance Method Details

#dispatchCommand(cmd, *arguments) ⇒ Object



Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
# File 'lib/utils/command-dispatcher.rb', line 37

def dispatchCommand(cmd, *arguments)

  raise ArgumentError.new(EX_NOCMD) if cmd == nil
  raise ArgumentError.new("#{cmd} " + EX_INVALCMD) unless isValid?(cmd)

  exec(@commandPrefix + cmd, *arguments)
end

#isValid?(command) ⇒ Boolean



Returns:

  • (Boolean)


47
48
49
50
# File 'lib/utils/command-dispatcher.rb', line 47

def isValid?(command)
  return false if (!File.exists?(@commandPrefix + command))
  return true
end

#usageObject





27
28
29
30
31
32
33
# File 'lib/utils/command-dispatcher.rb', line 27

def usage()
  Dir.glob(@commandPrefix + '*').each do |f|
    help = `#{f} --usage`
    command = File.basename(f).gsub!( "-", " " )
    $stdout.puts command.ljust(25)  + " : " + help 
  end
end