Class: Wip::CLI

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

Instance Method Summary collapse

Instance Method Details

#complete(todo_id) ⇒ Object



14
15
16
17
# File 'lib/wip/cli.rb', line 14

def complete(todo_id)
  todo = options.undo ? Wip::Todo.uncomplete(todo_id) : Wip::Todo.complete(todo_id)
  puts todo.description
end

#delete(todo_id) ⇒ Object



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

def delete(todo_id)
  todo = Wip::Todo.delete(todo_id)
  puts todo.description
end

#done(body) ⇒ Object



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

def done(body)
  todo = Wip::Todo.create(body: body, completed_at: DateTime.now)
  puts todo.description
end

#meObject



32
33
34
# File 'lib/wip/cli.rb', line 32

def me
   Wip::User.viewer(todos: { "order" => "created_at:desc" })
end

#todo(body) ⇒ Object



37
38
39
40
# File 'lib/wip/cli.rb', line 37

def todo(body)
  todo = Wip::Todo.create(body: body)
  puts todo.description
end

#todosObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/wip/cli.rb', line 49

def todos
  todos_options = options.slice("completed", "filter", "limit", "order")
  user = options.username.nil? ? Wip::User.viewer(todos: todos_options) : Wip::User.find(username: options.username, todos: todos_options)
  if options.interactive
    prompt = TTY::Prompt.new
    options = user.todos.inject({}) do |h, todo|
      h[todo.description] = todo.id
      h
    end
    choice = prompt.multi_select("Toggle todos?", options, per_page: todos_options["limit"])
    puts "No change" if choice.empty?
    choice.each do |todo_id|
      todo = user.todos.find { |todo| todo.id == todo_id }
      todo.toggle
      puts todo.description
    end
  else
    user.todos.each { |todo| puts todo.description }
  end
end

#user(identifier) ⇒ Object



71
72
73
74
# File 'lib/wip/cli.rb', line 71

def user(identifier)
  user = identifier.to_i > 0 ? Wip::User.find(identifier.to_i) : Wip::User.find(username: identifier)
   user
end