Class: WorkGuide::CLI
- Inherits:
-
Thor
- Object
- Thor
- WorkGuide::CLI
- Defined in:
- lib/work_guide/cli.rb
Instance Method Summary collapse
- #add(description) ⇒ Object
- #delete(index) ⇒ Object
- #done(*args) ⇒ Object
- #list ⇒ Object
- #update(index) ⇒ Object
Instance Method Details
#add(description) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/work_guide/cli.rb', line 8 def add(description) guide = Guide.create( description: description, cycle: [:cycle] ) puts "Created [#{Guide.all.size - 1}]#{guide}" end |
#delete(index) ⇒ Object
33 34 35 36 37 |
# File 'lib/work_guide/cli.rb', line 33 def delete(index) guide = Guide.all.delete_at(index.to_i) Guide.save puts "Deleted [#{index}]#{guide}" end |
#done(*args) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/work_guide/cli.rb', line 41 def done(*args) indexes = args.dup if indexes.empty? IO.popen("peco", "r+") do |io| io.puts guide_table io.close_write index = io.gets.split("|")[1] if index && index =~ /\d/ indexes << index.strip else abort "[ERROR] Please select guide index !!" end end end guides = indexes.map { |index| Guide.all[index.to_i] } done_at = if [:at] Time.parse([:at]) else Time.now end guides.each do |guide| guide.done_at = done_at end Guide.save indexes.each do |index| puts "Done [#{index}]#{Guide.all[index.to_i]}" end end |
#list ⇒ Object
27 28 29 |
# File 'lib/work_guide/cli.rb', line 27 def list puts guide_table(all: [:all]) end |
#update(index) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/work_guide/cli.rb', line 18 def update(index) guide = Guide.all[index.to_i] guide.priority = [:priority] if [:priority] Guide.save puts "Update [#{index}]#{guide}" end |