-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathopt_parser2.rb
More file actions
executable file
·59 lines (47 loc) · 1.49 KB
/
opt_parser2.rb
File metadata and controls
executable file
·59 lines (47 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
#!/usr/bin/env ruby
require 'optparse'
require 'date'
options = {}
opt_parser = OptionParser.new do |opt|
opt.banner = "Usage: opt_parser COMMAND [OPTIONS]"
opt.separator ""
opt.separator "Commands"
opt.separator " start: start server"
opt.separator " stop: stop server"
opt.separator " restart: restart server"
opt.separator ""
opt.separator "Options"
opt.on("-e ENVIRONMENT","--environment ENVIRONMENT",Numeric,"which enviroment you want server run") do |environment|
options[:environment] = environment
end
opt.on("-d","--daemon","runing on daemon mode?") do
options[:daemon] = true
end
opt.on("--delay N", Float, "Delay N seconds before executing") do |n|
options[:delay] = n
end
opt.on("-j x,y,z","--jurisdictions x,y,z", Array, "which jurisdiction will start") do |jurisdictions|
options[:jurisdictions] = jurisdictions
end
server_list = %w[a b c]
opt.on("-s SERVERS","--servers SERVERS", server_list, "which server will start between #{server_list.join(',')}") do |servers|
options[:servers] = servers
end
opt.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
end
opt.on_tail("-h","--help","help") do
puts opt_parser
end
end
opt_parser.parse!
case ARGV[0]
when "start"
puts "call start on options #{options.inspect}"
when "stop"
puts "call stop on options #{options.inspect}"
when "restart"
puts "call restart on options #{options.inspect}"
else
puts opt_parser
end