Class: Appsignal::CLI Private

Inherits:
Object show all
Defined in:
lib/appsignal/cli.rb,
lib/appsignal/cli/demo.rb,
lib/appsignal/cli/helpers.rb,
lib/appsignal/cli/install.rb,
lib/appsignal/cli/diagnose.rb,
lib/appsignal/cli/diagnose/paths.rb,
lib/appsignal/cli/diagnose/utils.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Modules: Helpers Classes: Demo, Diagnose, Install

Constant Summary collapse

AVAILABLE_COMMANDS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[demo diagnose install].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
# File 'lib/appsignal/cli.rb', line 17

def options
  @options
end

Class Method Details

.command_option_parserObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/appsignal/cli.rb', line 67

def command_option_parser
  {
    "demo" => OptionParser.new do |o|
      o.banner = "Usage: appsignal demo [options]"

      o.on "--environment=<app_env>", "The environment to demo" do |arg|
        options[:environment] = arg
      end
    end,
    "diagnose" => OptionParser.new do |o|
      o.banner = "Usage: appsignal diagnose [options]"

      o.on "--environment=<app_env>", "The environment to diagnose" do |arg|
        options[:environment] = arg
      end
      o.on "--[no-]send-report", "Confirm sending the report to AppSignal automatically" do |arg|
        options[:send_report] = arg
      end
      o.on "--[no-]color", "Colorize the output of the diagnose command" do |arg|
        options[:color] = arg
      end
    end,
    "install" => OptionParser.new do |o|
      o.on "--[no-]color", "Colorize the output of the diagnose command" do |arg|
        options[:color] = arg
      end
    end
  }
end

.global_option_parserObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/appsignal/cli.rb', line 48

def global_option_parser
  OptionParser.new do |o|
    o.banner = "Usage: appsignal <command> [options]"

    o.on "-v", "--version", "Print version and exit" do |_arg|
      puts "AppSignal #{Appsignal::VERSION}"
      exit(0)
    end

    o.on "-h", "--help", "Show help and exit" do
      puts o
      exit(0)
    end

    o.separator ""
    o.separator "Available commands: #{AVAILABLE_COMMANDS.join(", ")}"
  end
end

.run(argv = ARGV) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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
# File 'lib/appsignal/cli.rb', line 19

def run(argv = ARGV)
  @options = {}
  global = global_option_parser
  commands = command_option_parser
  global.order!(argv)
  command = argv.shift
  if command
    if AVAILABLE_COMMANDS.include?(command)
      commands[command].parse!(argv)
      case command.to_sym
      when :demo
        Appsignal::CLI::Demo.run(options)
      when :diagnose
        Appsignal::CLI::Diagnose.run(options)
      when :install
        Appsignal::CLI::Install.run(argv.shift, options)
      end
    else
      puts "Command '#{command}' does not exist, run appsignal -h to "\
        "see the help"
      exit(1)
    end
  else
    # Print help
    puts global
    exit(0)
  end
end