Class: TrakFlow::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/trak_flow/cli.rb,
lib/trak_flow/cli/dep_commands.rb,
lib/trak_flow/cli/main_commands.rb,
lib/trak_flow/cli/plan_commands.rb,
lib/trak_flow/cli/admin_commands.rb,
lib/trak_flow/cli/label_commands.rb,
lib/trak_flow/cli/config_commands.rb,
lib/trak_flow/cli/workflow_commands.rb

Defined Under Namespace

Classes: AdminCommands, ConfigCommands, DepCommands, LabelCommands, PlanCommands, WorkflowCommands

Instance Method Summary collapse

Instance Method Details

#close(id) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/trak_flow/cli/main_commands.rb', line 157

def close(id)
  with_database do |db|
    task = db.find_task!(id)
    task.close!(reason: options[:reason])
    db.update_task(task)

    output(task.to_h) do
      puts "Closed: #{pastel.bold(task.id)} - #{task.title}"
    end
  end
end

#create(title) ⇒ Object

Raises:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/trak_flow/cli/main_commands.rb', line 73

def create(title)
  validate_option!(:type, TrakFlow::TYPES, options[:type])
  validate_option!(:priority, TrakFlow::PRIORITIES, options[:priority])
  raise ValidationError, "Plans cannot be ephemeral" if options[:plan] && options[:ephemeral]

  with_database do |db|
    task = build_task(db, title, resolve_description)
    attach_labels(db, task)
    attach_dependencies(db, task)

    output(task.to_h) do
      puts "Created: #{pastel.bold(task.id)} - #{task.title}"
    end
  end
end

#infoObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/trak_flow/cli/main_commands.rb', line 45

def info
  TrakFlow.ensure_initialized!

  info_data = {
    database_path: TrakFlow.database_path,
    jsonl_path: TrakFlow.jsonl_path,
    config_path: TrakFlow.config_path,
    initialized: TrakFlow.initialized?
  }

  output(info_data) do
    info_data.each { |k, v| puts "#{k}: #{v}" }
  end
end

#initObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/trak_flow/cli/main_commands.rb', line 15

def init
  trak_dir = TrakFlow.trak_flow_dir

  if TrakFlow.initialized?
    output({ success: false, error: "TrakFlow already initialized" }) do
      puts pastel.red("Error: TrakFlow already initialized in #{trak_dir}")
    end
    return
  end

  FileUtils.mkdir_p(trak_dir)

  db = Storage::Database.new
  db.connect

  TrakFlow.config.set("stealth", options[:stealth])

  jsonl = Storage::Jsonl.new
  jsonl.write_entities([])

  setup_gitignore unless options[:stealth]

  output({ success: true, path: trak_dir }) do
    puts pastel.green("Initialized TrakFlow in #{trak_dir}")
  end
end

#listObject



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/trak_flow/cli/main_commands.rb', line 116

def list
  with_database do |db|
    tasks = filtered_tasks(db)

    output(tasks.map(&:to_h)) do
      if tasks.empty?
        puts "No tasks found"
      else
        print_tasks_table(tasks)
      end
    end
  end
end

#readyObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/trak_flow/cli/main_commands.rb', line 188

def ready
  with_database do |db|
    tasks = db.ready_tasks

    output(tasks.map(&:to_h)) do
      if tasks.empty?
        puts "No ready tasks found"
      else
        puts pastel.bold("Ready for work:")
        print_tasks_table(tasks)
      end
    end
  end
end

#reopen(id) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/trak_flow/cli/main_commands.rb', line 173

def reopen(id)
  with_database do |db|
    task = db.find_task!(id)
    task.reopen!(reason: options[:reason])
    db.update_task(task)

    output(task.to_h) do
      puts "Reopened: #{pastel.bold(task.id)} - #{task.title}"
    end
  end
end

#show(id) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/trak_flow/cli/main_commands.rb', line 92

def show(id)
  with_database do |db|
    task = db.find_task!(id)
    labels = db.find_labels(id)
    deps = db.find_dependencies(id)
    comments = db.find_comments(id)

    output({ task: task.to_h, labels: labels.map(&:name), dependencies: deps.map(&:to_h), comments: comments.map(&:to_h) }) do
      print_task_details(task, labels, deps, comments)
    end
  end
end

#staleObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/trak_flow/cli/main_commands.rb', line 208

def stale
  with_database do |db|
    tasks = db.stale_tasks(days: options[:days], status: options[:status])

    output(tasks.map(&:to_h)) do
      if tasks.empty?
        puts "No stale tasks found"
      else
        puts pastel.bold("Stale tasks (#{options[:days]}+ days):")
        print_tasks_table(tasks)
      end
    end
  end
end

#syncObject



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/trak_flow/cli/main_commands.rb', line 226

def sync
  with_database do |db|
    jsonl = Storage::Jsonl.new
    jsonl_path = jsonl.path

    if jsonl.exists?
      jsonl.import(db)
      output({ success: true, action: "imported", path: jsonl_path }) do
        puts pastel.green("Imported from #{jsonl_path}")
      end
    end

    jsonl.export(db)
    output({ success: true, action: "exported", path: jsonl_path }) do
      puts pastel.green("Exported to #{jsonl_path}")
    end

    unless TrakFlow.config.get("stealth") || TrakFlow.config.get("no_push")
      git_commit_and_push
    end
  end
end

#update(id) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/trak_flow/cli/main_commands.rb', line 138

def update(id)
  validate_option!(:status, TrakFlow::STATUSES, options[:status])
  validate_option!(:priority, TrakFlow::PRIORITIES, options[:priority])

  with_database do |db|
    task = db.find_task!(id)
    apply_task_updates(task)
    db.update_task(task)

    output(task.to_h) do
      puts "Updated: #{pastel.bold(task.id)} - #{task.title}"
    end
  end
end

#versionObject



7
8
9
# File 'lib/trak_flow/cli/main_commands.rb', line 7

def version
  puts "trak_flow #{VERSION}"
end