Class: Bosh::Cli::Command::Base
- Extended by:
- Bosh::Cli::CommandDiscovery
- Defined in:
- lib/cli/base_command.rb
Direct Known Subclasses
Biff, BlobManagement, CloudCheck, Complete, Deployment, Help, Job, JobManagement, JobRename, LogManagement, Maintenance, Misc, Package, PropertyManagement, Release, Ssh, Stemcell, Task, User, Vms
Constant Summary collapse
- DEFAULT_DIRECTOR_PORT =
25555
Instance Attribute Summary collapse
-
#args ⇒ Array
Arguments passed to command handler.
-
#options ⇒ Object
readonly
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
-
#cache ⇒ Bosh::Cli::Cache
Current CLI cache.
-
#config ⇒ Bosh::Cli::Config
Current configuration.
- #confirmed?(question = "Are you sure?") ⇒ Boolean
-
#deployment ⇒ String
Deployment manifest path.
- #director ⇒ Object
-
#exit_code(code = nil) ⇒ Object
Sets or returns command exit code.
-
#initialize(runner = 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
-
#task_report(status, task_id, success_msg = nil, error_msg = nil) ⇒ Object
Prints director task completion report.
-
#username ⇒ String
Director username.
- #verbose? ⇒ Boolean
Methods included from Bosh::Cli::CommandDiscovery
desc, method_added, option, register_command, usage
Constructor Details
#initialize(runner = nil) ⇒ Base
Returns a new instance of Base.
20 21 22 23 24 25 26 27 |
# File 'lib/cli/base_command.rb', line 20 def initialize(runner = nil) @runner = runner @options = {} @work_dir = Dir.pwd @exit_code = 0 @out = nil @args = [] end |
Instance Attribute Details
#args ⇒ Array
Returns Arguments passed to command handler.
15 16 17 |
# File 'lib/cli/base_command.rb', line 15 def args @args end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/cli/base_command.rb', line 8 def @options end |
#out ⇒ Object
Returns the value of attribute out.
12 13 14 |
# File 'lib/cli/base_command.rb', line 12 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.
9 10 11 |
# File 'lib/cli/base_command.rb', line 9 def work_dir @work_dir end |
Instance Method Details
#add_option(name, value) ⇒ Object
42 43 44 |
# File 'lib/cli/base_command.rb', line 42 def add_option(name, value) @options[name] = value end |
#blob_manager ⇒ Object
61 62 63 |
# File 'lib/cli/base_command.rb', line 61 def blob_manager @blob_manager ||= Bosh::Cli::BlobManager.new(release) end |
#blobstore ⇒ Object
65 66 67 |
# File 'lib/cli/base_command.rb', line 65 def blobstore release.blobstore end |
#cache ⇒ Bosh::Cli::Cache
Returns Current CLI cache.
30 31 32 |
# File 'lib/cli/base_command.rb', line 30 def cache Config.cache end |
#config ⇒ Bosh::Cli::Config
Returns Current configuration.
35 36 37 38 39 40 |
# File 'lib/cli/base_command.rb', line 35 def config @config ||= begin config_file = [:config] || Bosh::Cli::DEFAULT_CONFIG_PATH Bosh::Cli::Config.new(config_file) end end |
#confirmed?(question = "Are you sure?") ⇒ Boolean
89 90 91 92 |
# File 'lib/cli/base_command.rb', line 89 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.
103 104 105 |
# File 'lib/cli/base_command.rb', line 103 def deployment [:deployment] || config.deployment end |
#director ⇒ Object
50 51 52 53 |
# File 'lib/cli/base_command.rb', line 50 def director @director ||= Bosh::Cli::Director.new( target, username, password, @options.select {|k,v| k == :no_track}) end |
#exit_code(code = nil) ⇒ Object
Sets or returns command exit code
124 125 126 127 128 129 130 |
# File 'lib/cli/base_command.rb', line 124 def exit_code(code = nil) if code @exit_code = code else @exit_code end end |
#interactive? ⇒ Boolean
77 78 79 |
# File 'lib/cli/base_command.rb', line 77 def interactive? !non_interactive? end |
#logged_in? ⇒ Boolean
69 70 71 |
# File 'lib/cli/base_command.rb', line 69 def logged_in? username && password end |
#non_interactive? ⇒ Boolean
73 74 75 |
# File 'lib/cli/base_command.rb', line 73 def non_interactive? [:non_interactive] end |
#password ⇒ String
Returns Director password.
113 114 115 |
# File 'lib/cli/base_command.rb', line 113 def password [:password] || ENV["BOSH_PASSWORD"] || config.password(target) end |
#redirect(*args) ⇒ Object
85 86 87 |
# File 'lib/cli/base_command.rb', line 85 def redirect(*args) Bosh::Cli::Runner.new(args, @options).run end |
#release ⇒ Object
55 56 57 58 59 |
# File 'lib/cli/base_command.rb', line 55 def release return @release if @release check_if_release_dir @release = Bosh::Cli::Release.new(@work_dir) end |
#remove_option(name) ⇒ Object
46 47 48 |
# File 'lib/cli/base_command.rb', line 46 def remove_option(name) @options.delete(name) end |
#target ⇒ String Also known as: target_url
Returns Target director URL.
95 96 97 98 99 |
# File 'lib/cli/base_command.rb', line 95 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
117 118 119 |
# File 'lib/cli/base_command.rb', line 117 def target_name config.target_name || target_url end |
#task_report(status, task_id, success_msg = nil, error_msg = nil) ⇒ Object
Prints director task completion report. Note that event log usually contains pretty detailed error report and other UI niceties, so most of the time this could just do nothing
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/cli/base_command.rb', line 137 def task_report(status, task_id, success_msg = nil, error_msg = nil) case status when :non_trackable report = "Can't track director task".red when :track_timeout report = "Task tracking timeout".red when :running report = "Director task #{task_id.yellow} is running" when :error report = error_msg when :done report = success_msg else report = nil end if status != :done exit_code(1) end say("\n#{report}") if report end |
#username ⇒ String
Returns Director username.
108 109 110 |
# File 'lib/cli/base_command.rb', line 108 def username [:username] || ENV["BOSH_USER"] || config.username(target) end |
#verbose? ⇒ Boolean
81 82 83 |
# File 'lib/cli/base_command.rb', line 81 def verbose? @options[:verbose] end |