module ThreeScaleToolbox::CLI

Public Class Methods

add_command(command) click to toggle source
# File lib/3scale_toolbox/cli.rb, line 12
def self.add_command(command)
  root_command.add_subcommand(command)
end
install_signal_handlers() click to toggle source
# File lib/3scale_toolbox/cli.rb, line 20
def self.install_signal_handlers
  # Set exit handler
  # Only OS supported signals
  available_signals = %w[INT TERM].select { |signal_name| Signal.list.key? signal_name }
  available_signals.each do |signal|
    Signal.trap(signal) do
      puts
      exit!(0)
    end
  end

  # Set stack trace dump handler
  if !defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby'
    if Signal.list.key? 'USR1'
      Signal.trap('USR1') do
        puts 'Caught USR1; dumping a stack trace'
        puts caller.map { |i| "  #{i}" }.join("\n")
      end
    end
  end
end
load_builtin_commands() click to toggle source
# File lib/3scale_toolbox/cli.rb, line 16
def self.load_builtin_commands
  ThreeScaleToolbox::Commands::BUILTIN_COMMANDS.each(&method(:add_command))
end
output_flag(dsl) click to toggle source
# File lib/3scale_toolbox/cli/output_flag.rb, line 16
def self.output_flag(dsl)
  dsl.option :o, :output, 'Output format. One of: json|yaml', argument: :required, transform: PrinterTransformer.new
end
root_command() click to toggle source
# File lib/3scale_toolbox/cli.rb, line 8
def self.root_command
  ThreeScaleToolbox::Commands::ThreeScaleCommand
end
run(args) click to toggle source
# File lib/3scale_toolbox/cli.rb, line 42
def self.run(args)
  install_signal_handlers
  err = ErrorHandler.error_watchdog do
    load_builtin_commands
    ThreeScaleToolbox.load_plugins
    root_command.build_command.run args
  end
  err.nil? ? 0 : 1
end