Sha256: 200051789af3290b7e5d6fd86563634a8693bcd734f7ae1454a59c03f2880ccd

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

require '3scale_toolbox/cli/error_handler'

module ThreeScaleToolbox::CLI
  def self.root_command
    ThreeScaleToolbox::Commands::ThreeScaleCommand
  end

  def self.add_command(command)
    root_command.add_subcommand(command)
  end

  def self.load_builtin_commands
    ThreeScaleToolbox::Commands::BUILTIN_COMMANDS.each(&method(:add_command))
  end

  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

  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
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
3scale_toolbox-0.15.0 lib/3scale_toolbox/cli.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/cli.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/cli.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/cli.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/cli.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/cli.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/cli.rb
3scale_toolbox-0.10.0 lib/3scale_toolbox/cli.rb
3scale_toolbox-0.9.0 lib/3scale_toolbox/cli.rb
3scale_toolbox-0.8.0 lib/3scale_toolbox/cli.rb