Module: Morpheus::Cli::PrintHelper

Included in:
Credentials
Defined in:
lib/morpheus/cli/mixins/print_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
# File 'lib/morpheus/cli/mixins/print_helper.rb', line 6

def self.included(klass)
  klass.send :include, Term::ANSIColor
end

Instance Method Details



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/morpheus/cli/mixins/print_helper.rb', line 75

def print_dry_run(request, payload)
  print "\n" ,cyan, bold, "DRY RUN\n","==================", "\n\n", reset
  print cyan
  print "Request: ", "\n"
  print reset
  print request.to_s, "\n\n"
  print cyan
  print "JSON: ", "\n"
  print reset
  print JSON.pretty_generate(payload)
  print "\n"
  print reset
end


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/morpheus/cli/mixins/print_helper.rb', line 22

def print_errors(response, options={})
  begin
    if options[:json]
      print red, "\n"
      print JSON.pretty_generate(response)
      print reset, "\n\n"
    else
      if !response['success']
        print red,bold, "\n"
        if response['msg']
          puts response['msg']
        end
        if response['errors']
          response['errors'].each do |key, value|
            print "* #{key}: #{value}\n"
          end
        end
        print reset, "\n"
      else
        # this should not really happen
        print cyan,bold, "\nSuccess!"
      end
    end
  ensure
    print reset
  end
end


18
19
20
# File 'lib/morpheus/cli/mixins/print_helper.rb', line 18

def print_green_success(msg)
  print green, bold, "\n#{msg}\n\n", reset
end


10
11
12
# File 'lib/morpheus/cli/mixins/print_helper.rb', line 10

def print_red_alert(msg)
  print red, bold, "\n#{msg}\n\n", reset
end


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/morpheus/cli/mixins/print_helper.rb', line 50

def print_rest_exception(e, options={})
  if e.response
    if e.response.code == 400
      response = JSON.parse(e.response.to_s)
      print_errors(response, options)
    else
      print_red_alert "Error Communicating with the Appliance. (#{e.response.code}) #{e}"
      if options[:json]
        begin
          response = JSON.parse(e.response.to_s)
          print red, "\n"
          print JSON.pretty_generate(response)
          print reset, "\n\n"
        rescue TypeError, JSON::ParserError => ex
          #print_red_alert "Failed to parse JSON response: #{ex}"
        ensure
          print reset
        end
      end
    end
  else
    print_red_alert "Error Communicating with the Appliance. #{e}"
  end
end


14
15
16
# File 'lib/morpheus/cli/mixins/print_helper.rb', line 14

def print_yellow_warning(msg)
  print yellow, bold, "\n#{msg}\n\n", reset
end

#required_blue_prompt ⇒ Object



89
90
91
# File 'lib/morpheus/cli/mixins/print_helper.rb', line 89

def required_blue_prompt
  "#{cyan}|#{reset}"
end