Class: Currently::Application

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

Instance Method Summary collapse

Instance Method Details

#runObject



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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/currently.rb', line 14

def run
  opts = Trollop::options do
    version "currently v#{VERSION} (c) 2011 Mike Stipicevic"
    banner <<-EOS
  currently is a 'concentration log' designed to keep track of what you
  are working or thinking about right at this moment.

  usage:
        currently [options] [entry]

  leaving out an entry will display the last one entered

  available [options] are:
EOS

    opt :filestore, "use local filestore", :type => :string
    opt :context, "select a context (work, home, etc)", :type => :string
    opt :catch, "use catch, specify username:password", :type => :string
  end

  unless opts[:catch]
    fname = ENV["HOME"] + "/.currentlog"
    fname = opts[:filestore] if opts[:filestore] 
    backingstore = Filestore.new(fname)
  else
    user = opts[:catch].split(":")[0]
    Trollop::die :catch, "must be in the format: username:password" if opts[:catch].split(":").length < 2
    pw = opts[:catch].split(":")[1]
    backingstore = Catchstore.new(user,pw)
  end

  if ARGV.count > 0
    text = ARGV.join(" ")
    if opts[:context]
      ent = Entry.new(text,[opts[:context]])
    else
      ent = Entry.new(text)
    end
    backingstore.save(ent)
  else
    if opts[:context]
      last = backingstore.last(1,opts[:context])
    else
      last = backingstore.last
    end
    if last.count > 0 then
      puts last.first.to_s
    else
      puts "[ entry log is empty ]"
    end
  end
end