Module: Moose::Inventory::Cli::Formatter
Instance Attribute Summary collapse
-
#indent ⇒ Object
—————.
Class Method Summary collapse
-
.dump(arg, format = 'json') ⇒ Object
rubocop:enable Style/ModuleFunction.
- .out(arg, format = 'json') ⇒ Object
Instance Method Summary collapse
- #error(msg) ⇒ Object
- #info(indent, msg, stream = 'STDOUT') ⇒ Object
- #print(indent, msg, stream = 'STDOUT') ⇒ Object
- #puts(indent, msg, stream = 'STDOUT') ⇒ Object
- #reset_indent ⇒ Object
- #warn(msg) ⇒ Object
Instance Attribute Details
#indent ⇒ Object
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 |
#print(indent, msg, stream = 'STDOUT') ⇒ Object
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_indent ⇒ Object
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 |