Module: DotFiles::Dispatch

Defined in:
lib/dot_files/dispatch.rb

Class Method Summary collapse

Class Method Details

.load_commandsObject



25
26
27
28
29
# File 'lib/dot_files/dispatch.rb', line 25

def load_commands
  Dir[File.join(File.dirname(__FILE__), 'commands', '*.rb')].each do |path|
    DotFiles::DSL.module_eval File.read(path), path
  end
end

.run(command, args = []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dot_files/dispatch.rb', line 5

def run(command, args = [])
  command = 'help' if command.nil?
  command = command.to_sym
  if DotFiles::DSL.commands[command]
    if args.size < DotFiles::DSL.commands[command][:required_args]
      puts "usage: #{DotFiles::DSL.commands[command][:usage]}"
    else
      DotFiles::DSL.commands[command][:block].call(*args)
    end
  else
    puts "Command not found. Check 'deploy help' for full information."
  end
rescue DotFiles::Errors::AccessDenied
  puts "Access Denied. The username & API key stored for your account was invalid. Have you run 'dotfiles setup' on this computer?"
  Process.exit(1)
rescue DotFiles::Error
  puts "An error occured with your request."
  Process.exit(1)
end