#!/usr/bin/env ruby require 'gli' include GLI::App subcommand_option_handling :normal sort_help :manually commands_from 'flapjack/cli' program_desc 'Flexible monitoring notification routing system' version Flapjack::VERSION desc 'Configuration file to use' default_value '/etc/flapjack/flapjack_config.yaml' arg_name '/path/to/flapjack.yaml' flag [:c,:config] desc 'Environment to boot' default_value 'production' arg_name '' flag [:n, :env, :environment] accept Array do |value| value.split(/,/).map(&:strip) end pre do |global,command,options,args| FLAPJACK_ENV = ENV["FLAPJACK_ENV"] || global[:environment] true end post do |global,command,options,args| end on_error do |exception| # We've changed the commands to control the flapjack server. If we detect # the user has tried one of the old commands, show them what they should # have used instead. SERVER_COMMANDS = %w(start stop restart reload status) message = exception.message input = message.split("'").last.downcase old_command = message.start_with?('Unknown command') && SERVER_COMMANDS.include?(input) if old_command puts exception.message puts "\nDid you mean: #{$PROGRAM_NAME} server #{input}?" puts "\nTry #{$PROGRAM_NAME} help" end # If this wasn't an old server command, return true to show the standard error dialog !old_command end exit run(ARGV)