Module: CfScript::Command::Runner

Included in:
Base
Defined in:
lib/cf_script/command/runner.rb

Class Method Summary collapse

Class Method Details

.cf_binObject



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_envObject



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_idObject



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

Returns:

  • (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/cf_script/command/runner.rb', line 27

def cf_in_path?
  !which_cf.empty?
end

.cf_pathObject



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_versionObject



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.message
end

.which_cfObject



23
24
25
# File 'lib/cf_script/command/runner.rb', line 23

def which_cf
  `which cf`.chomp
end