Class: TrakFlow::CLI::PlanCommands

Inherits:
Thor
  • Object
show all
Defined in:
lib/trak_flow/cli/plan_commands.rb

Overview

Plan subcommands (workflow blueprints)

Instance Method Summary collapse

Instance Method Details

#add(plan_id, title) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/trak_flow/cli/plan_commands.rb', line 81

def add(plan_id, title)
  with_database do |db|
    plan = db.find_task!(plan_id)
    raise Error, "#{plan_id} is not a Plan" unless plan.plan?

    task = db.create_child_task(plan_id, {
      title: title,
      description: options[:description] || "",
      type: options[:type],
      priority: options[:priority]
    })

    output(task.to_h) do
      puts "Added Task to Plan: #{task.id} - #{task.title}"
    end
  end
end

#convert(id) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/trak_flow/cli/plan_commands.rb', line 112

def convert(id)
  with_database do |db|
    task = db.find_task!(id)
    raise Error, "Task is already a Plan" if task.plan?
    raise Error, "Cannot convert ephemeral tasks to Plans" if task.ephemeral?

    db.mark_as_plan(id)
    task = db.find_task!(id)

    output(task.to_h) do
      puts "Converted to Plan: #{task.id}"
    end
  end
end

#create(title) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/trak_flow/cli/plan_commands.rb', line 13

def create(title)
  with_database do |db|
    plan = Models::Task.new(
      title: title,
      description: options[:description] || "",
      type: options[:type],
      priority: options[:priority],
      plan: true
    )
    db.create_task(plan)

    output(plan.to_h) do
      puts "Created Plan: #{plan.id} - #{plan.title}"
    end
  end
end

#execute(plan_id) ⇒ Object



107
108
109
# File 'lib/trak_flow/cli/plan_commands.rb', line 107

def execute(plan_id)
  instantiate_plan(plan_id, ephemeral: true)
end

#listObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/trak_flow/cli/plan_commands.rb', line 32

def list
  with_database do |db|
    if options[:workflows]
      items = db.find_workflows
      label = "Workflows"
    else
      items = db.find_plans
      label = "Plans"
    end

    output(items.map(&:to_h)) do
      if items.empty?
        puts "No #{label.downcase} found"
      else
        puts "#{label}:"
        items.each do |item|
          status_info = item.plan? ? "" : " (#{item.status})"
          ephemeral_tag = item.ephemeral? ? " [ephemeral]" : ""
          puts "  #{item.id}: #{item.title}#{status_info}#{ephemeral_tag}"
        end
      end
    end
  end
end

#show(id) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/trak_flow/cli/plan_commands.rb', line 58

def show(id)
  with_database do |db|
    plan = db.find_task!(id)
    tasks = db.find_plan_tasks(id)

    output({ plan: plan.to_h, tasks: tasks.map(&:to_h) }) do
      puts "Plan: #{plan.id} - #{plan.title}"
      puts "Description: #{plan.description.empty? ? "(none)" : plan.description}"
      puts ""
      puts "Tasks (#{tasks.size}):"
      if tasks.empty?
        puts "  (no tasks defined)"
      else
        tasks.each { |task| puts "  #{task.id}: #{task.title} (P#{task.priority})" }
      end
    end
  end
end

#start(plan_id) ⇒ Object



101
102
103
# File 'lib/trak_flow/cli/plan_commands.rb', line 101

def start(plan_id)
  instantiate_plan(plan_id, ephemeral: false)
end