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
|
# File 'lib/core/options.rb', line 7
def self.parse(args)
options = {
daemon: false,
server: true,
server_command: nil,
generate: false,
template: nil,
generate_name: nil,
host: {}
}
parser = OptionParser.new do |opts|
opts.banner = "Usage: #{Zashoku::CConf[:app][:name]} [options]"
opts.on('-s [COMMAND]', '--server [COMMAND]', 'pass commands to the server') do |cmd|
options[:server] = true
options[:server_command] = cmd || 'start'
end
opts.on('-d', '--daemon', 'daemonize the server') do |d|
options[:daemon] = true
end
if Zashoku::CConf[:app][:name] == 'zashoku'
opts.on('-g TEMPLATE', '--generate TEMPLATE', 'generate a template') do |template|
options[:template] = template
options[:generate] = true
end
end
opts.on('-H HOST', '--host HOST', 'specify host') do |host|
options[:host][:host] = host.split(':').first
options[:host][:port] = host.split(':').last
end
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
end
opts.on_tail('--version', 'Show version') do
puts Zashoku::Version.join('.')
exit
end
end
parser.parse!(args)
options[:generate_name] = args.pop if options[:template]
options
end
|