Class: Tasku::CLI::App
- Inherits:
-
Thor
- Object
- Thor
- Tasku::CLI::App
- Defined in:
- lib/tasku/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add ⇒ Object
- #categories ⇒ Object
- #delete(id) ⇒ Object
- #done(id) ⇒ Object
- #edit(id) ⇒ Object
- #list ⇒ Object
- #projects ⇒ Object
- #show(id) ⇒ Object
- #stats ⇒ Object
- #version ⇒ Object
Class Method Details
Instance Method Details
#add ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tasku/cli.rb', line 41 def add attrs = if [:interactive] || .values_at(:name, :description, :project, :category).all?(&:nil?) interactive_add else option_add end task = Task.create(attrs) terminal.render_added(task) rescue Sequel::ValidationFailed => e abort pastel.red("Validation error: #{e.}") end |
#categories ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/tasku/cli.rb', line 197 def categories categories = Task.dataset.select(:category).where(Sequel.~(category: nil)).distinct.order(:category).map(:category) if categories.empty? puts pastel.yellow(" No categories found.") return end puts "" categories.each do |c| count = Task.where(category: c).count puts " #{pastel.bold(c)} #{pastel.dim("(#{count} task(s))")}" end puts "" end |
#delete(id) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/tasku/cli.rb', line 161 def delete(id) task = find_task(id) unless [:force] prompt = TTY::Prompt.new confirmed = prompt.yes?(pastel.red("Delete task ##{id} (#{task.name})?")) return unless confirmed end task.destroy terminal.render_deleted(task) end |
#done(id) ⇒ Object
153 154 155 156 157 |
# File 'lib/tasku/cli.rb', line 153 def done(id) task = find_task(id) task.update(status: "done") terminal.render_updated(task) end |
#edit(id) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/tasku/cli.rb', line 117 def edit(id) task = find_task(id) attrs = option_edit if attrs.empty? && ![:clear] puts pastel.yellow("No changes specified. Use --help to see available options.") return end if [:clear] clear_fields = [:clear].split(",").map(&:strip) clear_map = { "description" => :description, "start" => :start_day, "due" => :due_day, "model" => :model_name, "tags" => :tags, "hours" => :estimated_hours } clear_fields.each do |f| col = clear_map[f] if col attrs[col] = nil else puts pastel.yellow("Unknown field to clear: #{f}") end end end task.update(attrs) terminal.render_updated(task) rescue Sequel::ValidationFailed => e abort pastel.red("Validation error: #{e.}") end |
#list ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/tasku/cli.rb', line 63 def list dataset = Task.dataset dataset = dataset.where(status: [:status]) if [:status] dataset = dataset.where(priority: [:priority]) if [:priority] dataset = dataset.where(project: [:project]) if [:project] dataset = dataset.where(category: [:category]) if [:category] if [:tags] tag_filter = [:tags].split(",").map(&:strip) tag_filter.each do |t| dataset = dataset.where(Sequel.ilike(:tags, "%#{t}%")) end end if [:overdue] today = Date.today dataset = dataset.where { due_day < today }.exclude(status: %w[done cancelled]) end sort_col = case [:sort] when "name" then :name when "priority" then Sequel.case(Task::VALID_PRIORITIES.each_with_index.to_h, 999, :priority) when "due" then :due_day when "status" then Sequel.case(Task::VALID_STATUSES.each_with_index.to_h, 999, :status) else :created_at end order = [:order] == "desc" ? Sequel.desc(sort_col) : Sequel.asc(sort_col) dataset = dataset.order(order) tasks = dataset.all terminal.render_list(tasks) end |
#projects ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/tasku/cli.rb', line 181 def projects projects = Task.dataset.select(:project).where(Sequel.~(project: nil)).distinct.order(:project).map(:project) if projects.empty? puts pastel.yellow(" No projects found.") return end puts "" projects.each do |p| count = Task.where(project: p).count puts " #{pastel.bold(p)} #{pastel.dim("(#{count} task(s))")}" end puts "" end |
#show(id) ⇒ Object
99 100 101 102 |
# File 'lib/tasku/cli.rb', line 99 def show(id) task = find_task(id) terminal.render_show(task) end |
#stats ⇒ Object
175 176 177 178 |
# File 'lib/tasku/cli.rb', line 175 def stats tasks = Task.dataset.all terminal.render_stats(tasks) if tasks end |