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, #parse_list_options, #parse_list_subtitles, #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
38
39
40
41
42
43
# 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
  if args.count == 1
    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
  end
  if Term::ANSIColor::coloring?
    puts "#{cyan}coloring is #{bold}#{green}on#{reset}"
  else
    puts "coloring is off"
  end
end