Class: Rubdo::CLI

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

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



5
6
7
8
9
# File 'lib/rubdo/cli.rb', line 5

def initialize
  todos = List.read(todo_file)
  @list = List.new(todos)
  @id = ARGV[1].to_i - 1
end

Instance Method Details

#addObject



11
12
13
14
15
16
17
18
# File 'lib/rubdo/cli.rb', line 11

def add
  if ARGV[1]
    @list.add ARGV[1]
  else
    Tempfile.open('new_task') { |tf| @list.add Rubdo::Editor.add(tf.path) }
  end
  save
end

#doneObject Also known as: rm



20
21
22
23
# File 'lib/rubdo/cli.rb', line 20

def done
  @list.done @id
  save
end

#editObject



31
32
33
34
35
# File 'lib/rubdo/cli.rb', line 31

def edit
  abort("not a valid id") if @id > @list.to_a.size
  Tempfile.open('new_description') { |tf| task.description = Rubdo::Editor.edit(tf.path, task.description) }
  save
end

#helpObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rubdo/cli.rb', line 37

def help
  puts <<-HELP
-----------------
add/a [task description] - Add a new task. If the description is empty, $EDITOR is opened
list/ls - Lists all tasks
done/d [task id] - Complete a task
edit/e [task id] - Opens up $EDITOR to edit the task description
remove/rm [task id] - Deletes the specific task, same as done
help - Prints out this information
  HELP
end

#listObject Also known as: ls



26
27
28
# File 'lib/rubdo/cli.rb', line 26

def list
  list_tasks unless @list.to_a.empty?
end