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



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

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


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

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


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

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

#required_blue_promptObject



71
72
73
# File 'lib/morpheus/cli/mixins/print_helper.rb', line 71

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