Class: Tamarillo::Command

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

Constant Summary collapse

DEFAULT_PATH =
'~/.tamarillo'
DEFAULT_COMMAND =
'status'
HELP_TEXT =
<<-EOS
Tamarillo v#{VERSION}

Commands:

$ tam status [--prompt]

Displays remainder of current pomodoro, use the prompt switch
to render a space-separated format for prompt integration. This
is the default command.

eg. 12:00 720 900


$ tam start

Starts a new pomodoro if none in progress.


$ tam stop
$ tam interrupt

Stops the current pomodoro if in progress.


$ tam config
$ tam config [duration=MINUTES]
$ tam config [notifier=TYPE]

Displays the current configuration, use to change then duration of 
each pomodoro in minutes or the type of notifier used. 

Notifiers: growl, speech, bell
EOS
VALID_COMMANDS =
%w[help status config start stop interrupt]

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



45
46
47
48
49
# File 'lib/tamarillo/command.rb', line 45

def initialize
  config = Tamarillo::Config.load(config_path)
  storage = Storage.new(tamarillo_path, config)
  @controller = Controller.new(config, storage)
end

Instance Method Details

#config(*args) ⇒ Object



78
79
80
81
82
# File 'lib/tamarillo/command.rb', line 78

def config(*args)
  params = Hash[args.map { |pair| pair.split('=', 2) }]
  @controller.update_config(params)
  puts @controller.config.to_yaml
end

#execute(*args) ⇒ Object



51
52
53
54
# File 'lib/tamarillo/command.rb', line 51

def execute(*args)
  command = parse_command_name!(args)
  send(command.to_sym, *args.drop(1))
end

#help(*args) ⇒ Object



56
57
58
# File 'lib/tamarillo/command.rb', line 56

def help(*args)
  puts HELP_TEXT
end

#interrupt(*args) ⇒ Object Also known as: stop



73
74
75
# File 'lib/tamarillo/command.rb', line 73

def interrupt(*args)
  @controller.interrupt_current_tomato
end

#start(*args) ⇒ Object



68
69
70
71
# File 'lib/tamarillo/command.rb', line 68

def start(*args)
  tomato = @controller.start_new_tomato
  status unless tomato.nil?
end

#status(*args) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/tamarillo/command.rb', line 60

def status(*args)
  format = Formats::HUMAN
  format = Formats::PROMPT if args.include?('--prompt')

  status = @controller.status(format)
  puts status unless status.nil?
end