add --regular-user flag to registration script

This commit is contained in:
Bruno Windels 2018-09-10 19:32:56 +02:00
parent 037a06e8f0
commit ceec6ce5f4

View file

@ -133,7 +133,7 @@ def register_new_user(user, password, server_location, shared_secret, admin):
print "Passwords do not match" print "Passwords do not match"
sys.exit(1) sys.exit(1)
if not admin: if admin is None:
admin = raw_input("Make admin [no]: ") admin = raw_input("Make admin [no]: ")
if admin in ("y", "yes", "true"): if admin in ("y", "yes", "true"):
admin = True admin = True
@ -163,7 +163,12 @@ if __name__ == "__main__":
parser.add_argument( parser.add_argument(
"-a", "--admin", "-a", "--admin",
action="store_true", action="store_true",
help="Register new user as an admin. Will prompt if omitted.", help="Register new user as an admin. Will prompt if --regular-user is not set.",
)
parser.add_argument(
"--regular-user",
action="store_true",
help="Register new user as a regular user.",
) )
group = parser.add_mutually_exclusive_group(required=True) group = parser.add_mutually_exclusive_group(required=True)
@ -197,4 +202,10 @@ if __name__ == "__main__":
else: else:
secret = args.shared_secret secret = args.shared_secret
register_new_user(args.user, args.password, args.server_url, secret, args.admin) if args.admin and args.regular_user:
print "Both --admin and --regular-user are set, choose either."
sys.exit(1)
admin = True if args.admin else False if args.regular_user else None
register_new_user(args.user, args.password, args.server_url, secret, admin)