Class: Morpheus::Cli::ColoringCommand

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

Overview

This is for use in dotfile scripts It allows you to turn colors on or off globally

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from CliCommand

#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_id_list, #print, #print_error, #puts, #puts_error, #raise_command_error, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!

Instance Method Details

#handle(args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/morpheus/cli/coloring_command.rb', line 12

def handle(args)
  append_newline = true
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = "Usage: morpheus #{command_name} [on|off]"
    #build_common_options(opts, options, [])
    opts.on('-h', '--help', "Prints this help" ) do
      puts opts
      exit
    end
    opts.footer = "Enable [on] or Disable [off] ANSI Colors for all output."
  end
  optparse.parse!(args)
  if args.count != 1
    puts optparse
    exit 1
  end
  is_on = ["on","true", "1"].include?(args[0].to_s.strip.downcase)
  is_off = ["off","false", "0"].include?(args[0].to_s.strip.downcase)
  if !is_on && !is_off
    puts optparse
    exit 1
  end
  Term::ANSIColor::coloring = is_on
  return true
end