class Morpheus::Cli::Echo

This is for use in dotfile scripts for printing It is also responsible for maintaining a map of variables that are also used in custom shell prompts.

Constants

COLOR_VARIABLE_MAP

Public Class Methods

recalculate_variable_map() click to toggle source
# File lib/morpheus/cli/commands/echo_command.rb, line 19
def self.recalculate_variable_map()
  var_map = {}
  if Term::ANSIColor.coloring?
    var_map.merge!(COLOR_VARIABLE_MAP)
  else
    COLOR_VARIABLE_MAP.each {|k,v| var_map[k] = "" }
  end

  appliance = ::Morpheus::Cli::Remote.load_active_remote()
  if appliance
    var_map.merge!({'%remote' => appliance[:name], '%remote_url' => (appliance[:host].to_s || appliance[:url].to_s), '%username' => appliance[:username].to_s})
  else
    var_map.merge!({'%remote' => '', '%remote_url' => '', '%username' => ''})
  end
  @output_variable_map = var_map
end
variable_map() click to toggle source
# File lib/morpheus/cli/commands/echo_command.rb, line 15
def self.variable_map
  @output_variable_map ||= recalculate_variable_map()
end

Public Instance Methods

handle(args) click to toggle source
# File lib/morpheus/cli/commands/echo_command.rb, line 36
def handle(args)
  append_newline = true
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = "Usage: morpheus #{command_name} [<message>]"
    opts.on( '-n', '--nonewline', "do not append a newline to your words" ) do
      append_newline = false
    end
    build_common_options(opts, options, [])
  end
  optparse.parse!(args)
  out = ""
  out << args.join(' ')

  self.class.variable_map.each do |k, v|
    out.gsub!(k.to_s, v.to_s)
  end
  if append_newline
    out << "\n"
  end
  # print out
  print cyan + out + reset
  return 0
end