2020-10-11 15:51:26 +02:00
|
|
|
require "option_parser"
|
|
|
|
|
2020-10-11 20:52:04 +02:00
|
|
|
opt_authd_admin = -> (parser : OptionParser) {
|
|
|
|
parser.on "-k file", "--key-file file", "Read the authd shared key from a file." do |file|
|
|
|
|
Context.shared_key = File.read(file).chomp
|
|
|
|
Baguette::Log.info "Key for admin operations: #{Context.shared_key}."
|
2020-10-11 15:51:26 +02:00
|
|
|
end
|
2020-10-11 20:52:04 +02:00
|
|
|
}
|
2020-10-11 15:51:26 +02:00
|
|
|
|
|
|
|
|
2020-10-11 20:52:04 +02:00
|
|
|
parser = OptionParser.new do |parser|
|
|
|
|
parser.banner = "usage: #{PROGRAM_NAME} command help"
|
|
|
|
parser.on "-v verbosity", "--verbosity v", "Verbosity. From 0 to 4 (debug)." do |v|
|
|
|
|
Baguette::Context.verbosity = v.to_i
|
|
|
|
Baguette::Log.info "verbosity = #{v}"
|
2020-10-11 15:51:26 +02:00
|
|
|
end
|
2020-10-11 20:52:04 +02:00
|
|
|
parser.on "-h", "--help", "Prints this help message." do
|
|
|
|
puts "usage: #{PROGRAM_NAME} command help"
|
|
|
|
puts parser
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
|
|
|
|
parser.on "user", "user" do
|
|
|
|
parser.banner = "Usage: user [add | mod | delete]"
|
|
|
|
parser.on "add", "add" do
|
|
|
|
Baguette::Log.info "user-add"
|
|
|
|
Context.command = "user-add"
|
|
|
|
# parser_user_add.call parser
|
|
|
|
# opt_profile.call parser
|
|
|
|
opt_authd_admin.call parser
|
|
|
|
parser.banner = "Usage: user-add user-id -e email -p phone [opt]"
|
|
|
|
|
|
|
|
parser.on "help", "Prints this help message." do
|
|
|
|
puts "usage: #{PROGRAM_NAME} user-add THINGS [options]"
|
|
|
|
puts parser
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
parser.on "mod", "mod" do
|
|
|
|
Baguette::Log.info "user-mod"
|
|
|
|
Context.command = "user-mod"
|
|
|
|
# opt_profile.call parser
|
|
|
|
opt_authd_admin.call parser
|
|
|
|
end
|
2020-10-11 15:51:26 +02:00
|
|
|
|
2020-10-11 20:52:04 +02:00
|
|
|
parser.on "delete", "Remove user." do
|
|
|
|
Baguette::Log.info "Remove user."
|
|
|
|
Context.command = "delete"
|
|
|
|
opt_authd_admin.call parser
|
|
|
|
end
|
2020-10-11 15:51:26 +02:00
|
|
|
end
|
|
|
|
|
2020-10-11 20:52:04 +02:00
|
|
|
parser.on "permissions", "Permissions." do
|
|
|
|
parser.banner = "Usage: permissions [check | set]"
|
|
|
|
parser.on "set", "Set permissions." do
|
|
|
|
Baguette::Log.info "Set permissions."
|
|
|
|
Context.command = "set-permissions"
|
|
|
|
opt_authd_admin.call parser
|
|
|
|
end
|
|
|
|
|
|
|
|
parser.on "check", "Check permissions." do
|
|
|
|
Baguette::Log.info "Check permissions."
|
|
|
|
Context.command = "check-permissions"
|
|
|
|
opt_authd_admin.call parser
|
|
|
|
end
|
2020-10-11 15:51:26 +02:00
|
|
|
end
|
|
|
|
|
2020-10-11 20:52:04 +02:00
|
|
|
# Do not require to be admin.
|
|
|
|
parser.on "registration", "Register a user." do
|
|
|
|
Baguette::Log.info "Register a user."
|
|
|
|
Context.command = "registration"
|
|
|
|
# opt_profile.call parser
|
|
|
|
# opt_authd_login.call parser
|
|
|
|
end
|
|
|
|
parser.unknown_args do |args|
|
|
|
|
if args.size > 0
|
|
|
|
Baguette::Log.warning "Unknown args: #{args}"
|
|
|
|
end
|
2020-10-11 15:51:26 +02:00
|
|
|
end
|
2020-10-11 20:52:04 +02:00
|
|
|
|
|
|
|
# parser.on "-p file", "--profile file", "Read the user profile from a file." do |file|
|
|
|
|
# profile_file = file
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# parser.on "-X user-password", "--user-password pass", "Read the new user password." do |pass|
|
|
|
|
# password = pass
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# parser.on "-K file", "--key-file file", "Read the authd shared key from a file." do |file|
|
|
|
|
# key_file = file
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# parser.on "-R", "--register", "Use a registration request instead of a add-user one." do
|
|
|
|
# register = true
|
|
|
|
# end
|
2020-10-11 15:51:26 +02:00
|
|
|
end
|
|
|
|
|
2020-10-11 20:52:04 +02:00
|
|
|
|
|
|
|
parser.parse
|