Class: Gigawatt::Options

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

Constant Summary collapse

SUB_COMMANDS =
%w(setup init start stop sync status log)

Class Method Summary collapse

Class Method Details

.parse!Object



5
6
7
8
9
10
11
12
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
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gigawatt/options.rb', line 5

def self.parse!
  version_string = File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).strip

  options = Trollop::options do
    version "88miles #{version_string}"
    stop_on SUB_COMMANDS
    banner <<-EOS
88 Miles Command line application - http://88miles.net

Usage:
  88miles [globaloptions] <subcommand> [options]

subcommands:
  setup:  Link your 88 Miles account to this program
  init:   Link a project to a directory
  start:  Punch in to the linked project
  stop:   Punch out of the linked project
  sync:   Refresh the local cache from the server
  status: Show the project timer
  log:    Print out the project shifts

globaloptions:
    EOS
    opt :settings, "Path to store 88 Miles settings", :default => Settings.defaults[:path], :type => :string
  end

  settings = Settings.new(options)
  if ARGV.length == 0
    Trollop::die "Please supply a subcommand"
  end

  cmd = ARGV.shift.strip

  case cmd
  when "setup"
    Gigawatt::Commands::Setup.run!(settings)
  when "init"
    Gigawatt::Commands::Init.run!(settings)
  when "start"
    Gigawatt::Commands::Start.run!(settings)
  when "stop"
    Gigawatt::Commands::Stop.run!(settings)
  when "sync"
    Gigawatt::Commands::Sync.run!(settings)
  when "status"
    Gigawatt::Commands::Status.run!(settings)
  when "log"
    Gigawatt::Commands::Log.run!(settings)
  else
    Trollop::die "Unknown subcommand #{cmd.inspect}"
  end
end