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