Class: Purse::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/purse/cli.rb

Constant Summary collapse

ACTION_PREFIX =
/^--/

Class Method Summary collapse

Class Method Details

.run(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/purse/cli.rb', line 13

def run(args)
  begin
    banner
    settings_exist?
    action = args.detect {|a| a =~ ACTION_PREFIX }
    args.reject! {|a| a == action}
    pocket_name, note_name = args[0], args[1]
    if !action.nil? && action != ''
      action = action.gsub(ACTION_PREFIX,'')
      send(action, *([pocket_name, note_name].compact))
    else
      case note_name
      when 'push'
        push(pocket_name)
      when 'pull'
        pull(pocket_name)
      when '' 
      when nil
        list(pocket_name)
      else
        find(pocket_name, note_name)
      end
    end
  rescue MissingFile
    say("Could not find note: #{pocket_name}/#{note_name}")
  rescue Git::GitExecuteError => e
    say(e)
  rescue NoMethodError => e
    say("Sorry, there is no action #{action}.\nTry purse --help for a list of commands. #{e}")
  end
  hr
end