Class: Toodledo::CommandLine::InteractiveCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/toodledo/command_line/interactive_command.rb

Overview

Runs the interactive client.

Instance Method Summary collapse

Methods inherited from BaseCommand

#client

Constructor Details

#initialize(client) ⇒ InteractiveCommand

Returns a new instance of InteractiveCommand.



10
11
12
13
14
# File 'lib/toodledo/command_line/interactive_command.rb', line 10

def initialize(client)
  super(client, 'interactive', false)
  self.short_desc = "Interactive client"
  self.description = "The interactive command line client."
end

Instance Method Details

#command_loop(session) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/toodledo/command_line/interactive_command.rb', line 22

def command_loop(session)
  loop do
    begin
      input = ask("> ") do |q|
        q.readline = true
      end
      
      input.strip!
      
      client.execute_command(session, input)            
    rescue Toodledo::ItemNotFoundError => infe
      puts "Item not found: #{infe}"
    rescue Toodledo::ServerError => se
      puts "Server Error: #{se}"
    rescue RuntimeError => re
      puts "Error: #{re}"      
    end
  end # loop    
end

#execute(args) ⇒ Object



16
17
18
19
20
# File 'lib/toodledo/command_line/interactive_command.rb', line 16

def execute(args)
  Toodledo.begin(client.logger) do |session|
    command_loop(session)
  end
end