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

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#indentObject




38
39
40
# File 'lib/moose_inventory/cli/formatter.rb', line 38

def indent
  @indent
end

Class Method Details

.dump(arg, format = 'json') ⇒ Object

rubocop:enable Style/ModuleFunction



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

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

.out(arg, format = 'json') ⇒ Object



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

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

  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



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

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

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



66
67
68
69
70
71
72
73
74
75
# File 'lib/moose_inventory/cli/formatter.rb', line 66

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


55
56
57
58
59
60
61
62
63
64
# File 'lib/moose_inventory/cli/formatter.rb', line 55

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



44
45
46
47
48
49
50
51
52
53
# File 'lib/moose_inventory/cli/formatter.rb', line 44

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

#reset_indentObject



40
41
42
# File 'lib/moose_inventory/cli/formatter.rb', line 40

def reset_indent
  @indent = 2
end

#warn(msg) ⇒ Object



77
78
79
# File 'lib/moose_inventory/cli/formatter.rb', line 77

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