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) ⇒ Prune

Returns a new instance of Prune.



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

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

Instance Method Details

#call(**options) ⇒ Object



28
29
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
# File 'lib/ace/overseer/cli/commands/prune.rb', line 28

def call(**options)
  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