Method: Evernotable::Command.run

Defined in:
lib/evernotable/command.rb

.run(cmd, arguments = [], env = :sandbox) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/evernotable/command.rb', line 27

def self.run(cmd, arguments=[], env=:sandbox)
  if cmd.nil? || cmd.empty? 
    output_with_bang("Use *evernotable help* for additional information.")
    exit(1)
  end
  unless valid?(cmd)
    output_with_bang("*#{cmd}* is not a valid evernotable command.")
    output_with_bang("Use *evernotable help* for additional information.")
    exit(1)
  else
    #instantiate command and invoke method on it
    method = arguments.shift || :help
    obj = eval("Evernotable::Command::#{cmd.capitalize}").new(arguments, env)
    obj.send(method)
  end
rescue CommandFailed => ex
  error "#{ex.message}"
rescue Interrupt => e
  error "\n[command canceled]"
end