Class: Bosh::Cli::Command::Base

Inherits:
Object
  • Object
show all
Extended by:
Bosh::Cli::CommandDiscovery
Includes:
DeploymentHelper
Defined in:
lib/cli/base_command.rb

Constant Summary collapse

DEFAULT_DIRECTOR_PORT =
25555

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Bosh::Cli::CommandDiscovery

desc, method_added, option, register_command, usage

Methods included from DeploymentHelper

#cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_must_exist_in_deployment, #job_unique_in_deployment?, #jobs_and_indexes, #latest_release_versions, #prepare_deployment_manifest, #prompt_for_job_and_index, #resolve_release_aliases, #warn_about_stemcell_changes

Constructor Details

#initialize(runner = nil, director = nil) ⇒ Base

Returns a new instance of Base.

Parameters:



15
16
17
18
19
20
21
22
23
# File 'lib/cli/base_command.rb', line 15

def initialize(runner = nil, director = nil)
  @runner = runner
  @director = director
  @options = {}
  @work_dir = Dir.pwd
  @exit_code = 0
  @out = nil
  @args = []
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



9
10
11
# File 'lib/cli/base_command.rb', line 9

def args
  @args
end

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



10
11
12
# File 'lib/cli/base_command.rb', line 10

def exit_code
  @exit_code
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/cli/base_command.rb', line 9

def options
  @options
end

#outObject

Returns the value of attribute out.



9
10
11
# File 'lib/cli/base_command.rb', line 9

def out
  @out
end

#runnerObject (readonly)

Returns the value of attribute runner.



10
11
12
# File 'lib/cli/base_command.rb', line 10

def runner
  @runner
end

#work_dirObject (readonly)

Returns the value of attribute work_dir.



10
11
12
# File 'lib/cli/base_command.rb', line 10

def work_dir
  @work_dir
end

Instance Method Details

#add_option(name, value) ⇒ Object



35
36
37
# File 'lib/cli/base_command.rb', line 35

def add_option(name, value)
  @options[name] = value
end

#blob_managerObject



54
55
56
# File 'lib/cli/base_command.rb', line 54

def blob_manager
  @blob_manager ||= Bosh::Cli::BlobManager.new(release)
end

#blobstoreObject



58
59
60
# File 'lib/cli/base_command.rb', line 58

def blobstore
  release.blobstore
end

#configBosh::Cli::Config

Returns Current configuration.

Returns:



26
27
28
29
30
31
32
33
# File 'lib/cli/base_command.rb', line 26

def config
  @config ||= begin
    # Handle the environment variable being set to the empty string.
    env_bosh_config = ENV['BOSH_CONFIG'].to_s.empty? ? nil : ENV['BOSH_CONFIG']
    config_file = options[:config] || env_bosh_config || Bosh::Cli::DEFAULT_CONFIG_PATH
    Bosh::Cli::Config.new(config_file)
  end
end

#confirmed?(question = 'Are you sure?') ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
# File 'lib/cli/base_command.rb', line 82

def confirmed?(question = 'Are you sure?')
  return true if non_interactive?
  ask("#{question} (type 'yes' to continue): ") == 'yes'
end

#deploymentString

Returns Deployment manifest path.

Returns:

  • (String)

    Deployment manifest path



96
97
98
# File 'lib/cli/base_command.rb', line 96

def deployment
  options[:deployment] || config.deployment
end

#directorObject



43
44
45
46
# File 'lib/cli/base_command.rb', line 43

def director
  @director ||= Bosh::Cli::Client::Director.new(
      target, username, password, @options.select { |k, _| k == :no_track })
end

#interactive?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/cli/base_command.rb', line 70

def interactive?
  !non_interactive?
end

#logged_in?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/cli/base_command.rb', line 62

def logged_in?
  !!(username && password)
end

#non_interactive?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/cli/base_command.rb', line 66

def non_interactive?
  options[:non_interactive]
end

#passwordString

Returns Director password.

Returns:

  • (String)

    Director password



106
107
108
# File 'lib/cli/base_command.rb', line 106

def password
  options[:password] || ENV['BOSH_PASSWORD'] || config.password(target)
end

#redirect(*args) ⇒ Object



78
79
80
# File 'lib/cli/base_command.rb', line 78

def redirect(*args)
  Bosh::Cli::Runner.new(args, @options).run
end

#releaseObject



48
49
50
51
52
# File 'lib/cli/base_command.rb', line 48

def release
  return @release if @release
  check_if_release_dir
  @release = Bosh::Cli::Release.new(@work_dir)
end

#remove_option(name) ⇒ Object



39
40
41
# File 'lib/cli/base_command.rb', line 39

def remove_option(name)
  @options.delete(name)
end

#targetString Also known as: target_url

Returns Target director URL.

Returns:

  • (String)

    Target director URL



88
89
90
91
92
# File 'lib/cli/base_command.rb', line 88

def target
  raw_url = options[:target] || config.target
  url = config.resolve_alias(:target, raw_url) || raw_url
  url ? normalize_url(url) : nil
end

#target_nameObject



110
111
112
# File 'lib/cli/base_command.rb', line 110

def target_name
  options[:target] || config.target_name || target_url
end

#usernameString

Returns Director username.

Returns:

  • (String)

    Director username



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

def username
  options[:username] || ENV['BOSH_USER'] || config.username(target)
end

#verbose?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/cli/base_command.rb', line 74

def verbose?
  @options[:verbose]
end