Class: Morpheus::Cli::DebugCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/commands/standard/debug_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_command_result, #parse_id_list, #parse_list_options, #parse_list_subtitles, #print, #print_error, #print_to_file, #puts, #puts_error, #raise_command_error, #render_with_format, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!

Instance Method Details

#handle(args) ⇒ Object



11
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/morpheus/cli/commands/standard/debug_command.rb', line 11

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', "Print this help" ) do
      puts opts
      exit
    end
    opts.footer = "Enable [on] or Disable [off] debugging for all output.\n" + 
                  "Use [on?] or [off?] to print the current value and exit accordingly." + "\n" +
                  "Pass no arguments to just print the current value."
  end
  optparse.parse!(args)
  if args.count > 1
    raise_command_error "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
  end
  
  exit_code = 0

  if args.count == 0
    # just print
  else
    subcmd = args[0].to_s.strip
    if subcmd == "on"
      Morpheus::Logging.set_log_level(Morpheus::Logging::Logger::DEBUG)
      ::RestClient.log = Morpheus::Logging.debug? ? Morpheus::Logging::DarkPrinter.instance : nil
    elsif subcmd == "off"
      Morpheus::Logging.set_log_level(Morpheus::Logging::Logger::INFO)
      ::RestClient.log = Morpheus::Logging.debug? ? Morpheus::Logging::DarkPrinter.instance : nil
    elsif subcmd == "on?"
      exit_code = Morpheus::Logging.debug? ? 0 : 1
    elsif subcmd == "off?"
      exit_code = Morpheus::Logging.debug? ? 1 : 0
    else
      puts optparse
      return 127
    end
  end
  unless options[:quiet]
    if Morpheus::Logging.debug?
      puts "#{cyan}debug: #{green}on#{reset}"
    else
      puts "#{cyan}debug: #{dark}off#{reset}"
    end
  end
  return exit_code
end