Class: Wip::CLI
- Inherits:
-
Thor
- Object
- Thor
- Wip::CLI
- Defined in:
- lib/wip/cli.rb
Instance Method Summary collapse
- #complete(todo_id) ⇒ Object
- #delete(todo_id) ⇒ Object
- #done(body) ⇒ Object
- #me ⇒ Object
- #todo(body) ⇒ Object
- #todos ⇒ Object
- #user(identifier) ⇒ Object
Instance Method Details
#complete(todo_id) ⇒ Object
14 15 16 17 |
# File 'lib/wip/cli.rb', line 14 def complete(todo_id) todo = .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 |
#me ⇒ Object
32 33 34 |
# File 'lib/wip/cli.rb', line 32 def me print_user_profile 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 |
#todos ⇒ Object
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 = .slice("completed", "filter", "limit", "order") user = .username.nil? ? Wip::User.viewer(todos: ) : Wip::User.find(username: .username, todos: ) if .interactive prompt = TTY::Prompt.new = user.todos.inject({}) do |h, todo| h[todo.description] = todo.id h end choice = prompt.multi_select("Toggle todos?", , per_page: ["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 |