lib/invoker/parsers/option_parser.rb in invoker-0.1.2 vs lib/invoker/parsers/option_parser.rb in invoker-1.0.0
- old
+ new
@@ -4,23 +4,36 @@
module Invoker
module Parsers
class OptionParser
def self.parse(args)
selected_command = nil
-
opts = Slop.parse(args, help: true) do
on :v, "Print the version" do
Invoker::Logger.puts Invoker::VERSION
end
+ on :p, :port=, "Port series to be used for starting rack servers", as: Integer
command 'start' do
banner "Usage : invoker start config.ini \n Start Invoker Process Manager"
+ on :p, :port=, "Port series to be used for starting rack servers", as: Integer
run do |cmd_opts, cmd_args|
- selected_command = OpenStruct.new(:command => 'start', :file => cmd_args.first)
+ port = cmd_opts.to_hash[:port] || 9000
+ selected_command = OpenStruct.new(
+ :command => 'start',
+ :file => cmd_args.first,
+ :port => port
+ )
end
end
+ command 'setup' do
+ banner "Usage : invoker setup \n Sets up firewall rules for subdomains"
+ run do |cmd_opts, cmd_args|
+ selected_command = OpenStruct.new(:command => 'setup')
+ end
+ end
+
command 'list' do
banner "Usage : invoker list\n List processes managed by invoker"
run do |cmd_opts, cmd_args|
selected_command = OpenStruct.new(:command => 'list')
end
@@ -52,30 +65,30 @@
on :s, :signal=, "Signal to send for killing the process, default is SIGINT", as: String
run do |cmd_opts, cmd_args|
signal_to_use = cmd_opts.to_hash[:signal] || 'INT'
selected_command = OpenStruct.new(
- :command => 'reload',
+ :command => 'reload',
:command_key => cmd_args.first,
:signal => signal_to_use
)
end
end
end
selected_command || create_default_command(args, opts)
end
-
# If user specifies no command either show help message or start the invoker
# process supervisor.
#
# @param args [Array] command line arguments
# @param opts [Slop::Options] Processed slop options
# @return [OpenStruct, false] returns default command or nil
def self.create_default_command(args, opts)
if args.first && File.exists?(args.first) && File.file?(args.first)
- OpenStruct.new(:command => "start", :file => args.first)
+ port = opts.to_hash[:port] || 9000
+ OpenStruct.new(:command => "start", :file => args.first, :port => port)
else
Invoker::Logger.puts opts.inspect
false
end
end