Class: Bosh::Cli::Command::Base
- Extended by:
- Bosh::Cli::CommandDiscovery
- Includes:
- DeploymentHelper
- Defined in:
- lib/cli/base_command.rb
Direct Known Subclasses
Backup, Biff, BlobManagement, CloudCheck, Complete, Deployment, Errand, ExportCompiledPackages, Help, ImportCompiledPackages, Job, JobManagement, JobRename, Locks, LogManagement, Maintenance, Misc, Package, PropertyManagement, Release::CreateRelease, Release::DeleteRelease, Release::InitRelease, Release::ListReleases, Release::ResetRelease, Release::UploadRelease, Release::VerifyRelease, Snapshot, Ssh, Stemcell, Task, User, Vm, Vms
Constant Summary collapse
- DEFAULT_DIRECTOR_PORT =
25555
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
-
#options ⇒ Object
Returns the value of attribute options.
-
#out ⇒ Object
Returns the value of attribute out.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
-
#work_dir ⇒ Object
readonly
Returns the value of attribute work_dir.
Instance Method Summary collapse
- #add_option(name, value) ⇒ Object
- #blob_manager ⇒ Object
- #blobstore ⇒ Object
-
#config ⇒ Bosh::Cli::Config
Current configuration.
- #confirmed?(question = 'Are you sure?') ⇒ Boolean
-
#deployment ⇒ String
Deployment manifest path.
- #director ⇒ Object
-
#initialize(runner = nil, director = nil) ⇒ Base
constructor
A new instance of Base.
- #interactive? ⇒ Boolean
- #logged_in? ⇒ Boolean
- #non_interactive? ⇒ Boolean
-
#password ⇒ String
Director password.
- #redirect(*args) ⇒ Object
- #release ⇒ Object
- #remove_option(name) ⇒ Object
-
#target ⇒ String
(also: #target_url)
Target director URL.
- #target_name ⇒ Object
-
#username ⇒ String
Director username.
- #verbose? ⇒ Boolean
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.
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
#args ⇒ Object
Returns the value of attribute args.
9 10 11 |
# File 'lib/cli/base_command.rb', line 9 def args @args end |
#exit_code ⇒ Object (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 |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/cli/base_command.rb', line 9 def @options end |
#out ⇒ Object
Returns the value of attribute out.
9 10 11 |
# File 'lib/cli/base_command.rb', line 9 def out @out end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
10 11 12 |
# File 'lib/cli/base_command.rb', line 10 def runner @runner end |
#work_dir ⇒ Object (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_manager ⇒ Object
54 55 56 |
# File 'lib/cli/base_command.rb', line 54 def blob_manager @blob_manager ||= Bosh::Cli::BlobManager.new(release) end |
#blobstore ⇒ Object
58 59 60 |
# File 'lib/cli/base_command.rb', line 58 def blobstore release.blobstore end |
#config ⇒ Bosh::Cli::Config
Returns Current configuration.
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 = [:config] || env_bosh_config || Bosh::Cli::DEFAULT_CONFIG_PATH Bosh::Cli::Config.new(config_file) end end |
#confirmed?(question = 'Are you sure?') ⇒ 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 |
#deployment ⇒ String
Returns Deployment manifest path.
96 97 98 |
# File 'lib/cli/base_command.rb', line 96 def deployment [:deployment] || config.deployment end |
#director ⇒ Object
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
70 71 72 |
# File 'lib/cli/base_command.rb', line 70 def interactive? !non_interactive? end |
#logged_in? ⇒ Boolean
62 63 64 |
# File 'lib/cli/base_command.rb', line 62 def logged_in? !!(username && password) end |
#non_interactive? ⇒ Boolean
66 67 68 |
# File 'lib/cli/base_command.rb', line 66 def non_interactive? [:non_interactive] end |
#password ⇒ String
Returns Director password.
106 107 108 |
# File 'lib/cli/base_command.rb', line 106 def password [: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 |
#release ⇒ Object
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 |
#target ⇒ String Also known as: target_url
Returns Target director URL.
88 89 90 91 92 |
# File 'lib/cli/base_command.rb', line 88 def target raw_url = [:target] || config.target url = config.resolve_alias(:target, raw_url) || raw_url url ? normalize_url(url) : nil end |
#target_name ⇒ Object
110 111 112 |
# File 'lib/cli/base_command.rb', line 110 def target_name [:target] || config.target_name || target_url end |
#username ⇒ String
Returns Director username.
101 102 103 |
# File 'lib/cli/base_command.rb', line 101 def username [:username] || ENV['BOSH_USER'] || config.username(target) end |
#verbose? ⇒ Boolean
74 75 76 |
# File 'lib/cli/base_command.rb', line 74 def verbose? @options[:verbose] end |