Class: Ace::Overseer::CLI::Commands::Prune

Inherits:
Support::Cli::Command
  • Object
show all
Includes:
Support::Cli::Base
Defined in:
lib/ace/overseer/cli/commands/prune.rb

Instance Method Summary collapse

Constructor Details

#initialize(orchestrator: nil, input: $stdin, output: $stdout, lab_client: nil) ⇒ Prune

Returns a new instance of Prune.



22
23
24
25
26
27
28
# File 'lib/ace/overseer/cli/commands/prune.rb', line 22

def initialize(orchestrator: nil, input: $stdin, output: $stdout, lab_client: nil)
  super()
  @orchestrator = orchestrator || Organisms::PruneOrchestrator.new
  @input = input
  @output = output
  @lab_client = lab_client || Molecules::LabClient.new
end

Instance Method Details

#call(**options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ace/overseer/cli/commands/prune.rb', line 30

def call(**options)
  runtime = options.fetch(:runtime, "tmux")
  if runtime == "lab"
    prune_lab(**options)
    return
  end
  raise Ace::Support::Cli::Error, "unsupported runtime: #{runtime}" unless runtime == "tmux"

  Atoms::RepoGuard.ensure_repo!

  targets = Array(options[:targets] || [])
  progress = options[:quiet] ? nil : ->(msg) { puts msg }
  result = @orchestrator.call(
    dry_run: options[:dry_run],
    yes: options[:yes],
    force: options[:force],
    targets: targets,
    assignment_id: options[:assignment],
    input: @input,
    output: @output,
    on_progress: progress
  )

  return if options[:quiet]

  if options[:assignment]
    print_assignment_result(result)
    return
  end

  if result[:dry_run]
    print_dry_run(result)
    return
  end

  if result[:aborted]
    puts "Prune aborted."
    return
  end

  print_apply(result)
rescue => e
  raise Ace::Support::Cli::Error.new(e.message)
end