Module: Evernotable::Command

Extended by:
Utilities
Defined in:
lib/evernotable/command.rb

Defined Under Namespace

Classes: Auth, Base, CommandFailed, Help, Task

Class Method Summary collapse

Methods included from Utilities

display, encrypt_key, error, format_with_bang, output_with_bang, read_from_file, wrap_enml, write_to_file

Class Method Details

.commandsObject



19
20
21
# File 'lib/evernotable/command.rb', line 19

def self.commands
  @@commands ||= []
end

.loadObject



11
12
13
14
15
16
17
# File 'lib/evernotable/command.rb', line 11

def self.load
  @@commands = []
  Dir[File.join(File.dirname(__FILE__), "command", "*.rb")].each do |file|
    require file
    @@commands << File.basename(file, '.*') 
  end
end

.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

.valid?(cmd) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/evernotable/command.rb', line 23

def self.valid?(cmd)
   @@commands.include?(cmd)
end