Class: TrakFlow::CLI::AdminCommands

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

Overview

Admin subcommands

Instance Method Summary collapse

Instance Method Details

#analyzeObject



77
78
79
80
81
82
# File 'lib/trak_flow/cli/admin_commands.rb', line 77

def analyze
  with_database do |db|
    analysis = Graph::DependencyGraph.new(db).analyze
    output(analysis) { print_analysis(analysis) }
  end
end

#cleanupObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/trak_flow/cli/admin_commands.rb', line 14

def cleanup
  with_database do |db|
    candidates = cleanup_candidates(db)
    count = candidates.size

    if candidates.empty?
      puts "No tasks to clean up"
      return
    end

    return print_cleanup_dry_run(candidates) if options[:dry_run]
    return unless options[:force] || confirm_cleanup?(count)

    delete_candidates(db, candidates)

    output({ deleted: count }) do
      puts "Deleted #{count} task(s)"
    end
  end
end

#compactObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/trak_flow/cli/admin_commands.rb', line 38

def compact
  with_database do |db|
    if options[:analyze]
      stats = compaction_stats(db)
      output(stats) do
        stats.each { |k, v| puts "#{k}: #{v}" }
      end
    elsif options[:apply]
      tombstone_old_closed_tasks(db)
      puts "Compaction complete"
    else
      puts "Use --analyze to see stats or --apply to compact"
    end
  end
end

#graphObject



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

def graph
  with_database do |db|
    dep_graph = Graph::DependencyGraph.new(db)

    graph_output = case options[:format]
                   when "svg" then dep_graph.to_svg(include_closed: options[:include_closed])
                   else dep_graph.to_dot(include_closed: options[:include_closed])
                   end

    if (output_path = options[:output])
      File.write(output_path, graph_output)
      puts "Graph written to #{output_path}"
    else
      puts graph_output
    end
  end
end