Class: RabbitWQ::Cli
- Inherits:
-
Object
- Object
- RabbitWQ::Cli
- Defined in:
- lib/rabbit_wq/cli.rb
Constant Summary collapse
- SUB_COMMANDS =
%w( restart start status stop )
- DEFAULT_CONFIG_PATH =
"/etc/#{APP_ID}/#{APP_ID}.conf"
- DEFAULT_LOG_PATH =
"/var/log/#{APP_ID}/#{APP_ID}.log"
- DEFAULT_PID_PATH =
"/var/run/#{APP_ID}/#{APP_ID}.pid"
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(args) ⇒ Cli
constructor
A new instance of Cli.
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ Cli
Returns a new instance of Cli.
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rabbit_wq/cli.rb', line 23 def initialize( args ) Trollop:: do version VERSION_COPYRIGHT <<-EOS #{APP_NAME} #{VERSION_COPYRIGHT} Usage: #{APP_ID} [command] [options] commands: #{SUB_COMMANDS.map { |sub_cmd| " #{sub_cmd}" }.join( "\n" )} (For help with a command: #{APP_ID} [command] -h) options: EOS stop_on SUB_COMMANDS end # Get the sub-command and its options # @cmd = ARGV.shift || '' @options = case( cmd ) when "restart" Trollop:: do opt :config, "The path for the config file", :type => String, :short => '-c', :default => DEFAULT_CONFIG_PATH opt :log_level, "The log level", :type => String, :default => 'info' opt :log, "The path for the log file", :type => String, :short => '-l', :default => DEFAULT_LOG_PATH opt :pid, "The path for the PID file", :type => String, :default => DEFAULT_PID_PATH opt :threads, "The number of threads", :type => Integer, :short => '-t' end when "start" Trollop:: do opt :config, "The path for the config file", :type => String, :short => '-c', :default => DEFAULT_CONFIG_PATH opt :interactive, "Execute the server in interactive mode", :short => '-i' opt :log_level, "The log level", :type => String, :default => 'info' opt :log, "The path for the log file", :type => String, :short => '-l', :default => DEFAULT_LOG_PATH opt :pid, "The path for the PID file", :type => String, :default => DEFAULT_PID_PATH opt :threads, "The number of threads", :type => Integer, :short => '-t' end when "status" Trollop:: do opt :pid, "The path for the PID file", :type => String, :default => DEFAULT_PID_PATH opt :quiet, "Do not prompt to remove an old PID file", :type => :boolean, :default => false, :short => '-q' end when "stop" Trollop:: do opt :pid, "The path for the PID file", :type => String, :default => DEFAULT_PID_PATH opt :quiet, "Do not prompt to remove an old PID file", :type => :boolean, :default => false, :short => '-q' end else Trollop::die "unknown command #{cmd.inspect}" end if cmd == 'start' unless [:interactive] Trollop::die( :config, "is required when running as daemon" ) unless [:config] Trollop::die( :log, "is required when running as daemon" ) unless [:log] Trollop::die( :pid, "is required when running as daemon" ) unless [:pid] end end if %w(restart status stop).include?( cmd ) Trollop::die( :pid, "is required" ) unless [:pid] end end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
9 10 11 |
# File 'lib/rabbit_wq/cli.rb', line 9 def cmd @cmd end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/rabbit_wq/cli.rb', line 9 def @options end |
Instance Method Details
#run ⇒ Object
90 91 92 |
# File 'lib/rabbit_wq/cli.rb', line 90 def run send( cmd ) end |