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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/puppet_forge_server/utils/option_parser.rb', line 46
def parse_options(args)
options = PuppetForgeServer::Utils::OptionParser.DEFAULT_OPTIONS
option_parser = ::OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename $0} [options]"
opts.version = PuppetForgeServer::VERSION
opts.on('-p', '--port PORT', "Port number to bind to (default: #{@@DEFAULT_PORT})") do |port|
options[:port] = port
end
opts.on('-b', '--bind HOST', "Host name or IP address to bind to (default: #{@@DEFAULT_HOST})") do |host|
options[:host] = host
end
opts.on('-D', '--daemonize', "Run server in the background (default: #{@@DEFAULT_DAEMONIZE})") do
options[:daemonize] = true
end
opts.on('--pidfile FILE', "Pid file location (default: #{@@DEFAULT_PID_FILE})") do |pidfile|
options[:pidfile] = pidfile
end
options[:backend] = {'Directory' => [], 'Proxy' => [], 'Source' => []}
opts.on('-m', '--module-dir DIR', 'Directory containing packaged modules (recursively searched)') do |module_dir|
options[:backend]['Directory'] << module_dir
end
opts.on('-x', '--proxy URL', 'Remote forge URL') do |url|
options[:backend]['Proxy'] << url
end
opts.on('--cache-basedir DIR', "Proxy module cache base directory (default: #{@@DEFAULT_CACHE_DIR})") do |cache_basedir|
options[:cache_basedir] = cache_basedir
end
opts.on('--ram-cache-ttl SECONDS', "The time to live in seconds for remote requests RAM cache (default: #{@@DEFAULT_RAM_CACHE_TTL})") do |ram_cache_ttl|
options[:ram_cache_ttl] = ram_cache_ttl
end
opts.on('--ram-cache-size ENTRIES', "The maximum number of enties in RAM cache for remote requests (default: #{@@DEFAULT_RAM_CACHE_SIZE})") do |ram_cache_size|
options[:ram_cache_size] = ram_cache_size
end
opts.on('--log-dir DIR', "Log directory (default: #{@@DEFAULT_LOG_DIR})") do |log_dir|
options[:log_dir] = log_dir
end
opts.on('--webui-root DIR', "Directory containing views and other public files used for web UI: #{@@DEFAULT_WEBUI_ROOT})") do |webui_root|
options[:webui_root] = webui_root
end
opts.on('--debug', 'Log everything into STDERR') do
options[:debug] = true
end
end
begin
option_parser.parse(args)
rescue ::OptionParser::InvalidOption => parse_error
raise PuppetForgeServer::Errors::Expected, parse_error.message + "\n" + option_parser.help
end
raise PuppetForgeServer::Errors::Expected, "Web UI directory doesn't exist: #{options[:webui_root]}" unless Dir.exists?(options[:webui_root])
if options[:daemonize]
options[:pidfile] = @@DEFAULT_PID_FILE unless options[:pidfile]
options[:log_dir] = @@DEFAULT_LOG_DIR unless options[:log_dir]
end
if options[:log_dir] && !options[:daemonize]
options[:debug] = true
end
return options
end
|