Class: Acception::Subscriber::Cli
- Inherits:
-
Object
- Object
- Acception::Subscriber::Cli
- Defined in:
- lib/acception/subscriber/cli.rb
Constant Summary collapse
- SUB_COMMANDS =
%w( restart start status stop )
- DEFAULT_CONFIG_PATH =
"/etc/ncite/#{APP_ID}.conf"- DEFAULT_LOG_PATH =
"/var/log/ncite/#{APP_ID}.log"- DEFAULT_PID_PATH =
"/var/run/ncite/#{APP_ID}.pid"- DEFAULT_NUMBER_OF_THREADS =
1
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.
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 89 90 |
# File 'lib/acception/subscriber/cli.rb', line 26 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_level, "The log level", :type => String, :default => 'info', :short => '-o' 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, :default => DEFAULT_NUMBER_OF_THREADS, :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', :short => '-o' 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, :default => DEFAULT_NUMBER_OF_THREADS, :short => '-t' end when "status" Trollop:: do opt :pid, "The path for the PID file", :type => String, :default => DEFAULT_PID_PATH end when "stop" Trollop:: do opt :pid, "The path for the PID file", :type => String, :default => DEFAULT_PID_PATH 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.
10 11 12 |
# File 'lib/acception/subscriber/cli.rb', line 10 def cmd @cmd end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/acception/subscriber/cli.rb', line 10 def @options end |
Instance Method Details
#run ⇒ Object
92 93 94 |
# File 'lib/acception/subscriber/cli.rb', line 92 def run send( cmd ) end |