Class: TrakFlow::CLI::LabelCommands
- Inherits:
-
Thor
- Object
- Thor
- TrakFlow::CLI::LabelCommands
- Defined in:
- lib/trak_flow/cli/label_commands.rb
Overview
Label subcommands
Instance Method Summary collapse
- #add(id, label_name) ⇒ Object
- #list(id) ⇒ Object
- #list_all ⇒ Object
- #remove(id, label_name) ⇒ Object
Instance Method Details
#add(id, label_name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/trak_flow/cli/label_commands.rb', line 10 def add(id, label_name) with_database do |db| label = Models::Label.new(task_id: id, name: label_name) db.add_label(label) output(label.to_h) do puts "Added label '#{label_name}' to #{id}" end end end |
#list(id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/trak_flow/cli/label_commands.rb', line 33 def list(id) with_database do |db| labels = db.find_labels(id) output(labels.map(&:to_h)) do if labels.empty? puts "No labels" else labels.each { |l| puts l.name } end end end end |
#list_all ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/trak_flow/cli/label_commands.rb', line 48 def list_all with_database do |db| labels = db.all_labels output(labels) do if labels.empty? puts "No labels" else labels.each { |l| puts l } end end end end |
#remove(id, label_name) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/trak_flow/cli/label_commands.rb', line 22 def remove(id, label_name) with_database do |db| count = db.remove_label(id, label_name) output({ removed: count }) do puts count.positive? ? "Removed label '#{label_name}' from #{id}" : "Label not found" end end end |