Class: Bosh::Cli::Command::DeploymentDiff

Inherits:
Base show all
Defined in:
lib/cli/commands/deployment_diff.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_DIRECTOR_PORT

Instance Attribute Summary

Attributes inherited from Base

#args, #exit_code, #info, #options, #out, #runner, #work_dir

Instance Method Summary collapse

Methods inherited from Base

#add_option, #blob_manager, #blobstore, #cache_dir, #config, #confirmed?, #credentials, #deployment, #director, #interactive?, #logged_in?, #non_interactive?, #progress_renderer, #redirect, #release, #remove_option, #run_nested_command, #show_current_state, #target, #target_name, #verbose?

Methods included from Bosh::Cli::CommandDiscovery

#desc, #method_added, #option, #register_command, #usage

Methods included from DeploymentHelper

#build_manifest, #cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_unique_in_deployment?, #jobs_and_indexes, #prepare_deployment_manifest, #prompt_for_errand_name, #prompt_for_job_and_index

Constructor Details

#initialize(director, manifest) ⇒ DeploymentDiff

Returns a new instance of DeploymentDiff.



3
4
5
6
# File 'lib/cli/commands/deployment_diff.rb', line 3

def initialize(director, manifest)
  @director = director
  @manifest = manifest
end

Instance Method Details



8
9
10
11
12
13
14
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cli/commands/deployment_diff.rb', line 8

def print(options)
  redact_diff = options[:redact_diff]

  begin
    changes = @director.diff_deployment(@manifest.name, @manifest.yaml, redact_diff)
    diff = changes['diff']
    error = changes['error']

    header('Detecting deployment changes')

    diff.each do |line_diff|
      formatted_line_diff, state = line_diff

      # colorization explicitly disabled
      if Bosh::Cli::Config.use_color?
        case state
          when 'added'
            say(formatted_line_diff.make_green)
          when 'removed'
            say(formatted_line_diff.make_red)
          else
            say(formatted_line_diff)
        end

      else
        case state
          when 'added'
            say('+ ' + formatted_line_diff)
          when 'removed'
            say('- ' + formatted_line_diff)
          else
            say('  ' + formatted_line_diff)
        end
      end
    end

    say(error) if error

    changes['context']
  rescue Bosh::Cli::ResourceNotFound
    inspect_deployment_changes(
      @manifest,
      redact_diff: redact_diff
    )

    nil
  end
end