module Moose::Inventory::Cli::Formatter

TODO: Documentation

Attributes

indent[RW]

Public Class Methods

dump(arg, format = nil) click to toggle source

rubocop:enable Style/ModuleFunction

# File lib/moose_inventory/cli/formatter.rb, line 15
def self.dump(arg, format = nil)
  out(arg, format)
end
out(arg, format = nil) click to toggle source
# 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

Public Instance Methods

error(msg) click to toggle source
# File lib/moose_inventory/cli/formatter.rb, line 85
def error(msg)
    $stderr.print "ERROR: #{msg}"
end
info(indent, msg, stream='STDOUT') click to toggle source
# 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') click to toggle source
puts(indent, msg, stream='STDOUT') click to toggle source
# 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() click to toggle source
# File lib/moose_inventory/cli/formatter.rb, line 44
def reset_indent
  @indent = 2
end
warn(msg) click to toggle source
# File lib/moose_inventory/cli/formatter.rb, line 81
def warn(msg)
    $stderr.print "WARNING: #{msg}"
end