Exception handling.

ipc07
Luka Vandervelden 2020-01-04 09:02:31 +01:00
parent e1c204b742
commit 0e9d595a23
1 changed files with 29 additions and 20 deletions

View File

@ -273,29 +273,38 @@ authd_storage = "storage"
authd_jwt_key = "nico-nico-nii" authd_jwt_key = "nico-nico-nii"
authd_registrations = false authd_registrations = false
OptionParser.parse do |parser| begin
parser.banner = "usage: authd [options]" OptionParser.parse do |parser|
parser.banner = "usage: authd [options]"
parser.on "-s directory", "--storage directory", "Directory in which to store users." do |directory| parser.on "-s directory", "--storage directory", "Directory in which to store users." do |directory|
authd_storage = directory authd_storage = directory
end
parser.on "-K file", "--key-file file", "JWT key file" do |file_name|
authd_jwt_key = File.read(file_name).chomp
end
parser.on "-R", "--allow-registrations" do
authd_registrations = true
end
parser.on "-h", "--help", "Show this help" do
puts parser
exit 0
end
end end
parser.on "-K file", "--key-file file", "JWT key file" do |file_name| AuthD::Service.new(authd_storage, authd_jwt_key).tap do |authd|
authd_jwt_key = File.read(file_name).chomp authd.registrations_allowed = authd_registrations
end end.run
rescue e : OptionParser::Exception
parser.on "-R", "--allow-registrations" do STDERR.puts e.message
authd_registrations = true rescue e
end STDERR.puts "exception raised: #{e.message}"
e.backtrace.try &.each do |line|
parser.on "-h", "--help", "Show this help" do STDERR << " - " << line << '\n'
puts parser
exit 0
end end
end end
AuthD::Service.new(authd_storage, authd_jwt_key).tap do |authd|
authd.registrations_allowed = authd_registrations
end.run