Module: CfScript::Command::Runner
- Included in:
- Base
- Defined in:
- lib/cf_script/command/runner.rb
Class Method Summary collapse
- .cf_bin ⇒ Object
- .cf_env ⇒ Object
- .cf_id ⇒ Object
- .cf_in_env? ⇒ Boolean
- .cf_in_path? ⇒ Boolean
- .cf_path ⇒ Object
- .cf_version ⇒ Object
- .run_cf(command, *args, &block) ⇒ Object
- .which_cf ⇒ Object
Class Method Details
.cf_bin ⇒ Object
19 20 21 |
# File 'lib/cf_script/command/runner.rb', line 19 def cf_bin @cf_bin ||= cf_in_path? && !cf_in_env? ? 'cf' : cf_path end |
.cf_env ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/cf_script/command/runner.rb', line 59 def cf_env # When things go wrong dump the output of cf to the terminal, and the # colors make it easier to read. ENV['CF_COLOR'] ||= CfScript.config.runtime.color ? 'true' : 'false' ENV['CF_TRACE'] ||= ENV['DEBUG'] ? 'true' : 'false' ENV end |
.cf_id ⇒ Object
11 12 13 |
# File 'lib/cf_script/command/runner.rb', line 11 def cf_id "#{cf_version} (path: #{cf_path})" end |
.cf_in_env? ⇒ Boolean
31 32 33 |
# File 'lib/cf_script/command/runner.rb', line 31 def cf_in_env? !ENV['CF_BINARY'].nil? end |
.cf_in_path? ⇒ Boolean
27 28 29 |
# File 'lib/cf_script/command/runner.rb', line 27 def cf_in_path? !which_cf.empty? end |
.cf_path ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cf_script/command/runner.rb', line 35 def cf_path @cf_path = nil unless defined? @cf_path unless @cf_path @cf_path = ENV['CF_BINARY'] || which_cf if @cf_path.nil? || @cf_path.empty? puts "Could not find the cf binary".colorize(:red) puts puts "If it isn't installed you need to install it first. You can " puts "find the latest release at:" puts puts " https://github.com/cloudfoundry/cli/releases".colorize(:cyan) puts puts "If cf is already installed, make sure its location is " puts "included in $PATH." raise "Could not find the cf binary" end end @cf_path end |
.cf_version ⇒ Object
15 16 17 |
# File 'lib/cf_script/command/runner.rb', line 15 def cf_version `#{cf_bin} --version`.chomp.split(' ')[1..-1].join(': ') end |
.run_cf(command, *args, &block) ⇒ Object
5 6 7 8 9 |
# File 'lib/cf_script/command/runner.rb', line 5 def run_cf(command, *args, &block) run_command(command, *args, &block) rescue CfScript::Command::Error => exception error command.name, exception. end |
.which_cf ⇒ Object
23 24 25 |
# File 'lib/cf_script/command/runner.rb', line 23 def which_cf `which cf`.chomp end |