Class: Morpheus::Cli::Echo

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/commands/standard/echo_command.rb

Overview

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.

Constant Summary collapse

COLOR_VARIABLE_MAP =
{'%cyan' => Term::ANSIColor.cyan, '%magenta' => Term::ANSIColor.magenta, '%red' => Term::ANSIColor.red, '%green' => Term::ANSIColor.green, '%yellow' => Term::ANSIColor.yellow, '%white' => Term::ANSIColor.white, '%dark' => Term::ANSIColor.dark, '%reset' => Term::ANSIColor.reset}

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CliCommand

#apply_options, #build_common_options, #build_option_type_options, #build_standard_add_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_id_list, #parse_list_options, #parse_list_subtitles, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Class Method Details

.recalculate_variable_mapObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/morpheus/cli/commands/standard/echo_command.rb', line 21

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_mapObject



17
18
19
# File 'lib/morpheus/cli/commands/standard/echo_command.rb', line 17

def self.variable_map
  @output_variable_map ||= recalculate_variable_map()
end

Instance Method Details

#handle(args) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/morpheus/cli/commands/standard/echo_command.rb', line 38

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