diff --git a/README.md b/README.md index 6e0b585..2168ccb 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,11 @@ To see which commands this would evaluate, just run `eessi init`. Create subshell in which EESSI is available and initialised -*(to be implemented)* +```shell +eessi shell --eessi-version 2025.06 +``` + +You *must* specify the EESSI version to use, there is no default value for this. ## Design goals diff --git a/src/eessi/cli/shell.py b/src/eessi/cli/shell.py index 6c9bd70..50f1a4e 100644 --- a/src/eessi/cli/shell.py +++ b/src/eessi/cli/shell.py @@ -7,20 +7,35 @@ import tempfile import typer from rich import print as rich_print +from typing import Annotated app = typer.Typer() +def report_error(msg, exit_code: int = 1): + """ + Report error and exit with specified non-zero exit code + """ + rich_print(f"[bold red]{msg}", file=sys.stderr) + if exit_code <= 0: + raise ValueError(f"Exit code should be positive non-zero integer, got {exit_code}") + sys.exit(exit_code) + + @app.command() -def shell(): +def shell( + eessi_version: Annotated[str, typer.Option(help="EESSI version")] = '', +): """ Create subshell in which EESSI is available and initialised """ + if not eessi_version: + report_error("EESSI version to use is not specified, which is required!") + init_file = tempfile.mkstemp()[1] with open(init_file, 'w') as fp: - fp.write("set -e; source /cvmfs/software.eessi.io/versions/2023.06/init/bash") + fp.write(f"set -e; source /cvmfs/software.eessi.io/versions/{eessi_version}/init/bash") res = subprocess.run(['/bin/bash', '--init-file', init_file]) if res.returncode != 0: - rich_print("[bold red]ERROR: Non-zero exit code detected for interactive shell!", file=sys.stderr) - sys.exit(res.returncode) + report_error("ERROR: Non-zero exit code detected for interactive shell!", exit_code=res.returncode)