Module: Moose::Inventory::Cli::Formatter

Extended by:
Formatter
Included in:
Formatter
Defined in:
lib/moose_inventory/cli/formatter.rb

Overview

TODO: Documentation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#indentObject




42
43
44
# File 'lib/moose_inventory/cli/formatter.rb', line 42

def indent
  @indent
end

Class Method Details

.dump(arg, format = nil) ⇒ Object

rubocop:enable Style/ModuleFunction



15
16
17
# File 'lib/moose_inventory/cli/formatter.rb', line 15

def self.dump(arg, format = nil)
  out(arg, format)
end

.out(arg, format = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/moose_inventory/cli/formatter.rb', line 19

def self.out(arg, format = nil)
  return if arg.nil?

  if format.nil?
    format = Moose::Inventory::Config._confopts[:format].downcase
  end
  
  case format
  when 'yaml','y'
    $stdout.puts arg.to_yaml

  when 'prettyjson','pjson','p'
    $stdout.puts JSON.pretty_generate(arg)

  when 'json','j'
    $stdout.puts arg.to_json

  else
    abort("Output format '#{format}' is not yet supported.")
  end
end

Instance Method Details

#error(msg) ⇒ Object



85
86
87
# File 'lib/moose_inventory/cli/formatter.rb', line 85

def error(msg)
    $stderr.print "ERROR: #{msg}"
end

#info(indent, msg, stream = 'STDOUT') ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/moose_inventory/cli/formatter.rb', line 70

def info(indent, msg, stream='STDOUT')
  case stream
  when 'STDOUT'
    $stdout.print "INFO: {msg}"
  when 'STDERR'
    $stderr.print "INFO: {msg}"
  else
    abort("Output stream '#{stream}' is not known.")
  end
end


59
60
61
62
63
64
65
66
67
68
# File 'lib/moose_inventory/cli/formatter.rb', line 59

def print(indent, msg, stream='STDOUT')
  case stream
  when 'STDOUT'
    $stdout.print msg.indent(indent)
  when 'STDERR'
    $stderr.print msg.indent(indent)
  else
    abort("Output stream '#{stream}' is not known.")
  end
end

#puts(indent, msg, stream = 'STDOUT') ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/moose_inventory/cli/formatter.rb', line 48

def puts(indent, msg, stream='STDOUT')
  case stream
  when 'STDOUT'
    $stdout.puts msg.indent(indent)
  when 'STDERR'
    $stderr.puts msg.indent(indent)
  else
    abort("Output stream '#{stream}' is not known.")
  end
end

#reset_indentObject



44
45
46
# File 'lib/moose_inventory/cli/formatter.rb', line 44

def reset_indent
  @indent = 2
end

#warn(msg) ⇒ Object



81
82
83
# File 'lib/moose_inventory/cli/formatter.rb', line 81

def warn(msg)
    $stderr.print "WARNING: #{msg}"
end