Skip to content
Snippets Groups Projects
Commit 1ad2c947 authored by Ashwin Kumar Karnad's avatar Ashwin Kumar Karnad
Browse files

update argparse to aloow init to work without release argument

parent 5015c533
No related branches found
No related tags found
1 merge request!83Create init command
spack-environments @ 91ba21f4
Subproject commit 91ba21f40ff9e635da15a4c154360f5e969d6fe4
......@@ -1098,8 +1098,9 @@ def initialize_environment(root_dir: Path) -> None:
# check if the root_dir is not already initialized
init_file = root_dir / config_vars["init_file"]
if init_file.exists():
logging.error(
f"Directory {str(root_dir)} is already initialized as a software root."
# warn using the print logger as the release dir may not yet prepared
logging.getLogger("print").warning(
f"Error: Directory {str(root_dir)} is already initialized."
)
sys.exit(1)
else:
......@@ -1130,9 +1131,8 @@ def main():
)
subparsers.required = True
list_of_cmds = [
("init", "Initialize the software stack in the current directory")(
"available", "What is available for installation?"
),
("init", "Initialize the software stack in the current directory"),
("available", "What is available for installation?"),
("install", "Install a software environment"),
# ("reinstall", "Reinstall a package_set"),
# ("remove", "Remove a package set"),
......@@ -1160,11 +1160,13 @@ def main():
)
else:
subp.add_argument(
"release",
type=str,
help="Release version to prepare, install, reinstall or remove",
)
# all commands except init need a release version
if cmd != "init":
subp.add_argument(
"release",
type=str,
help="Release version to prepare, install, reinstall or remove",
)
if cmd in ["install", "reinstall", "remove"]:
# "install" command needs additional documentation
package_set_help = (
......@@ -1194,18 +1196,21 @@ def main():
# root dir is the place where this script is called from
root_dir = Path(os.getcwd())
set_up_logging(
args.loglevel,
get_installer_log_file_path(args.release, args.action, root_dir),
)
# set up logging for all actions except init
if args.action != "init":
set_up_logging(
args.loglevel,
get_installer_log_file_path(args.release, args.action, root_dir),
)
# sanity check for common mistakes in command line arguments
if args.release.endswith("/"): # happens easily with autocompletion
logging.error(
f"You provided mpsd-release='{args.release}'. "
f"Did you mean '{args.release.removesuffix('/')}'?"
)
sys.exit(1)
if args.action != "init":
if args.release.endswith("/"): # happens easily with autocompletion
logging.error(
f"You provided mpsd-release='{args.release}'. "
f"Did you mean '{args.release.removesuffix('/')}'?"
)
sys.exit(1)
# Check the command and run related function
if args.action == "init":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment