diff --git a/invokeai/app/util/user_management.py b/invokeai/app/util/user_management.py index 8f8a4d01d8c..24b1fe91ab9 100644 --- a/invokeai/app/util/user_management.py +++ b/invokeai/app/util/user_management.py @@ -12,8 +12,15 @@ import argparse import getpass import json +import os import sys +_root_help = ( + "Path to the InvokeAI root directory. If omitted, the root is resolved in this order: " + "the $INVOKEAI_ROOT environment variable, the active virtual environment's parent directory, " + "or $HOME/invokeai." +) + # --------------------------------------------------------------------------- # useradd # --------------------------------------------------------------------------- @@ -129,6 +136,7 @@ def useradd() -> None: description="Add a user to the InvokeAI database", epilog="If no arguments are provided, the script will run in interactive mode.", ) + parser.add_argument("--root", "-r", help=_root_help) parser.add_argument("--email", "-e", help="User email address") parser.add_argument("--password", "-p", help="User password") parser.add_argument("--name", "-n", help="User display name (optional)") @@ -136,6 +144,9 @@ def useradd() -> None: args = parser.parse_args() + if args.root: + os.environ["INVOKEAI_ROOT"] = args.root + if args.email or args.password: if not args.email or not args.password: print("❌ Error: Both --email and --password are required when using CLI mode") @@ -255,11 +266,15 @@ def userdel() -> None: description="Delete a user from the InvokeAI database", epilog="If no arguments are provided, the script will run in interactive mode.", ) + parser.add_argument("--root", "-r", help=_root_help) parser.add_argument("--email", "-e", help="User email address") parser.add_argument("--force", "-f", action="store_true", help="Delete without confirmation prompt") args = parser.parse_args() + if args.root: + os.environ["INVOKEAI_ROOT"] = args.root + if args.email: success = _delete_user_cli(args.email, args.force) else: @@ -358,6 +373,7 @@ def userlist() -> None: invoke-userlist --json """, ) + parser.add_argument("--root", "-r", help=_root_help) parser.add_argument( "--json", action="store_true", @@ -366,6 +382,9 @@ def userlist() -> None: args = parser.parse_args() + if args.root: + os.environ["INVOKEAI_ROOT"] = args.root + success = _list_users_json() if args.json else _list_users_table() sys.exit(0 if success else 1) @@ -532,6 +551,7 @@ def usermod() -> None: description="Modify a user in the InvokeAI database", epilog="If no arguments are provided, the script will run in interactive mode.", ) + parser.add_argument("--root", "-r", help=_root_help) parser.add_argument("--email", "-e", help="User email address") parser.add_argument("--name", "-n", help="New display name") parser.add_argument("--password", "-p", help="New password") @@ -542,6 +562,9 @@ def usermod() -> None: args = parser.parse_args() + if args.root: + os.environ["INVOKEAI_ROOT"] = args.root + is_admin = None if args.admin: is_admin = True