Class: CfScript::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Runner, UI, UI::NameTag, Singleton
Defined in:
lib/cf_script/command/base.rb

Constant Summary

Constants included from UI

UI::COLORS, UI::EMOJI, UI::TAGS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UI::NameTag

#alert, #detail, #error, #info, #name_tag, #progress, #step, #success, #title

Methods included from UI

alert, call_type, debug, detail, emoji, emoji_for, error, info, print_err, print_out, progress, puts_err, puts_out, step, success, tag_char, tag_close, tag_color, tag_format, tag_open, tag_style, title, trace, ui_format, with_color_of

Methods included from Runner

cf_bin, cf_env, cf_id, cf_in_env?, cf_in_path?, cf_path, cf_version, run_cf, which_cf

Constructor Details

#initialize(type, name) ⇒ Base

Returns a new instance of Base.



15
16
17
18
# File 'lib/cf_script/command/base.rb', line 15

def initialize(type, name)
  @type = type
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/cf_script/command/base.rb', line 8

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/cf_script/command/base.rb', line 7

def type
  @type
end

Instance Method Details

#good_run?(output, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cf_script/command/base.rb', line 32

def good_run?(output, options = {})
  options[:check_status] = option_value(options, :check_status, true)
  options[:check_failed] = option_value(options, :check_failed, true)

  if options[:check_status] == true && !output.good?
    error 'cf exited with error'
    output.dump unless CfScript.config.runtime.echo_output
    return false
  end

  if output.no_api_endpoint?
    error "No API endpoint set"
    return false
  end

  if output.not_logged_in?
    error 'Not logged in'
    return false
  end

  if options[:check_failed] == true && output.failed?
    error 'FAILED'
    output.dump unless CfScript.config.runtime.echo_output
    return false
  end

  true
end

#line(env, bin, args) ⇒ Object



20
21
22
# File 'lib/cf_script/command/base.rb', line 20

def line(env, bin, args)
  Line.new(env, bin, type, name, args)
end

#option_value(options, key, default) ⇒ Object



28
29
30
# File 'lib/cf_script/command/base.rb', line 28

def option_value(options, key, default)
  options.key?(key) ? options[key] : default
end

#run(*args, &block) ⇒ Object



24
25
26
# File 'lib/cf_script/command/base.rb', line 24

def run(*args, &block)
  raise "run called in base command class"
end