From 2f878e735962145982df191c4e354077a8e2cd56 Mon Sep 17 00:00:00 2001 From: Alex Domingo Date: Thu, 29 Jan 2026 21:25:21 +0100 Subject: [PATCH 1/5] move help option to top of help panel by using custom option --- src/eessi/cli/main.py | 51 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/src/eessi/cli/main.py b/src/eessi/cli/main.py index c794be7..192191d 100644 --- a/src/eessi/cli/main.py +++ b/src/eessi/cli/main.py @@ -2,39 +2,72 @@ # # authors: Kenneth Hoste (Ghent University) +import click import typer +from rich import print as rich_print +from typer import rich_utils import eessi from eessi.cli.check import app as check_app from eessi.cli.init import app as init_app from eessi.cli.shell import app as shell_app + +def version_callback(value: bool): + """ + Show version and exit early. + """ + if value: + rich_print(f"[bold]eessi[/bold] version {eessi.__version__}") + raise typer.Exit() + +def help_callback(ctx: click.Context, param: click.Parameter, value: bool): + """ + Show default help with rich and exit early. + """ + # ensures this doesn't run during completion or other early parsing phases + if not value or ctx.resilient_parsing: + return + + # print default help with rich + rich_utils.rich_format_help(obj=ctx.command, ctx=ctx, markup_mode="rich") + ctx.exit() + app = typer.Typer( help="User-friendly command line interface to EESSI - https://eessi.io", - context_settings={"help_option_names": ["-h", "--help"]}, + # display help if no arguments given no_args_is_help=True, + # we use custom help option to control its placement + add_help_option=False, ) app.add_typer(check_app) app.add_typer(init_app) app.add_typer(shell_app) -def version_callback(value: bool): - if value: - print(f"eessi version {eessi.__version__}") - raise typer.Exit() - @app.callback() def main( + help: bool = typer.Option( + None, # default value + "-h", + "--help", + help="Show this message and exit.", + callback=help_callback, + is_eager=True, + ), version: bool = typer.Option( None, # default value - "-v", # short option - "--version", # long option - help="Show version of eessi CLI", + "-v", + "--version", + help="Show version of eessi CLI.", callback=version_callback, + is_eager=True, ), ): + """ + Top level eessi command + """ pass From b3fc4022ce8ce56366a49c26654784cfbab11f6c Mon Sep 17 00:00:00 2001 From: Alex Domingo Date: Thu, 29 Jan 2026 21:53:58 +0100 Subject: [PATCH 2/5] move callback functions for help panel into eessi.cli.help module --- src/eessi/cli/help.py | 31 +++++++++++++++++++++++++++++++ src/eessi/cli/main.py | 26 +------------------------- 2 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 src/eessi/cli/help.py diff --git a/src/eessi/cli/help.py b/src/eessi/cli/help.py new file mode 100644 index 0000000..184b948 --- /dev/null +++ b/src/eessi/cli/help.py @@ -0,0 +1,31 @@ +# license (SPDX): GPL-2.0-only +# +# authors: Kenneth Hoste (Ghent University) + +import click +import typer +from rich import print as rich_print +from typer import rich_utils + +import eessi + + +def version_callback(value: bool): + """ + Show version and exit early. + """ + if value: + rich_print(f"[bold]eessi[/bold] version {eessi.__version__}") + raise typer.Exit() + +def help_callback(ctx: click.Context, param: click.Parameter, value: bool): + """ + Show default help with rich and exit early. + """ + # ensures this doesn't run during completion or other early parsing phases + if not value or ctx.resilient_parsing: + return + + # print default help with rich + rich_utils.rich_format_help(obj=ctx.command, ctx=ctx, markup_mode="rich") + ctx.exit() diff --git a/src/eessi/cli/main.py b/src/eessi/cli/main.py index 192191d..9d35324 100644 --- a/src/eessi/cli/main.py +++ b/src/eessi/cli/main.py @@ -2,37 +2,13 @@ # # authors: Kenneth Hoste (Ghent University) -import click import typer -from rich import print as rich_print -from typer import rich_utils -import eessi from eessi.cli.check import app as check_app +from eessi.cli.help import help_callback, version_callback from eessi.cli.init import app as init_app from eessi.cli.shell import app as shell_app - -def version_callback(value: bool): - """ - Show version and exit early. - """ - if value: - rich_print(f"[bold]eessi[/bold] version {eessi.__version__}") - raise typer.Exit() - -def help_callback(ctx: click.Context, param: click.Parameter, value: bool): - """ - Show default help with rich and exit early. - """ - # ensures this doesn't run during completion or other early parsing phases - if not value or ctx.resilient_parsing: - return - - # print default help with rich - rich_utils.rich_format_help(obj=ctx.command, ctx=ctx, markup_mode="rich") - ctx.exit() - app = typer.Typer( help="User-friendly command line interface to EESSI - https://eessi.io", # display help if no arguments given From 80df99d4b7d3510af315f1099b6301fe3db2a90a Mon Sep 17 00:00:00 2001 From: Alex Domingo Date: Thu, 29 Jan 2026 21:54:21 +0100 Subject: [PATCH 3/5] enable short -h to display help on all subcommands --- src/eessi/cli/check.py | 13 ++++++++++++- src/eessi/cli/init.py | 14 +++++++++++++- src/eessi/cli/shell.py | 14 +++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/eessi/cli/check.py b/src/eessi/cli/check.py index 3eef1e3..6f37bd6 100644 --- a/src/eessi/cli/check.py +++ b/src/eessi/cli/check.py @@ -4,11 +4,22 @@ import typer +from eessi.cli.help import help_callback + app = typer.Typer() @app.command() -def check(): +def check( + help: bool = typer.Option( + None, # default value + "-h", + "--help", + help="Show this message and exit.", + callback=help_callback, + is_eager=True, + ), +): """ Check CernVM-FS setup for accessing EESSI """ diff --git a/src/eessi/cli/init.py b/src/eessi/cli/init.py index 8f63dd0..ab5c279 100644 --- a/src/eessi/cli/init.py +++ b/src/eessi/cli/init.py @@ -4,13 +4,25 @@ import os import sys + import typer +from eessi.cli.help import help_callback + app = typer.Typer() @app.command() -def init(): +def init( + help: bool = typer.Option( + None, # default value + "-h", + "--help", + help="Show this message and exit.", + callback=help_callback, + is_eager=True, + ), +): """ Initialize shell environment for using EESSI """ diff --git a/src/eessi/cli/shell.py b/src/eessi/cli/shell.py index 6c9bd70..50096e0 100644 --- a/src/eessi/cli/shell.py +++ b/src/eessi/cli/shell.py @@ -5,14 +5,26 @@ import subprocess import sys import tempfile + import typer from rich import print as rich_print +from eessi.cli.help import help_callback + app = typer.Typer() @app.command() -def shell(): +def shell( + help: bool = typer.Option( + None, # default value + "-h", + "--help", + help="Show this message and exit.", + callback=help_callback, + is_eager=True, + ), +): """ Create subshell in which EESSI is available and initialised """ From 3b0ed67dcf7f70c94bab0f9bc1a25042edcec3ac Mon Sep 17 00:00:00 2001 From: Alex Domingo Date: Fri, 30 Jan 2026 11:38:00 +0100 Subject: [PATCH 4/5] add lexming to list of authors --- src/eessi/cli/help.py | 4 +++- src/eessi/cli/main.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/eessi/cli/help.py b/src/eessi/cli/help.py index 184b948..aa8221a 100644 --- a/src/eessi/cli/help.py +++ b/src/eessi/cli/help.py @@ -1,6 +1,8 @@ # license (SPDX): GPL-2.0-only # -# authors: Kenneth Hoste (Ghent University) +# authors: +# - Kenneth Hoste (Ghent University) +# - Alex Domingo (Vrije Universiteit Brussel) import click import typer diff --git a/src/eessi/cli/main.py b/src/eessi/cli/main.py index 9d35324..801ba01 100644 --- a/src/eessi/cli/main.py +++ b/src/eessi/cli/main.py @@ -1,6 +1,8 @@ # license (SPDX): GPL-2.0-only # -# authors: Kenneth Hoste (Ghent University) +# authors: +# - Kenneth Hoste (Ghent University) +# - Alex Domingo (Vrije Universiteit Brussel) import typer From a13e10062d984789951344b81b1f0d44deeabb6e Mon Sep 17 00:00:00 2001 From: Alex Domingo Date: Fri, 30 Jan 2026 11:38:29 +0100 Subject: [PATCH 5/5] place help_callback at the top --- src/eessi/cli/help.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/eessi/cli/help.py b/src/eessi/cli/help.py index aa8221a..38b6f3d 100644 --- a/src/eessi/cli/help.py +++ b/src/eessi/cli/help.py @@ -12,14 +12,6 @@ import eessi -def version_callback(value: bool): - """ - Show version and exit early. - """ - if value: - rich_print(f"[bold]eessi[/bold] version {eessi.__version__}") - raise typer.Exit() - def help_callback(ctx: click.Context, param: click.Parameter, value: bool): """ Show default help with rich and exit early. @@ -31,3 +23,12 @@ def help_callback(ctx: click.Context, param: click.Parameter, value: bool): # print default help with rich rich_utils.rich_format_help(obj=ctx.command, ctx=ctx, markup_mode="rich") ctx.exit() + +def version_callback(value: bool): + """ + Show version and exit early. + """ + if value: + rich_print(f"[bold]eessi[/bold] version {eessi.__version__}") + raise typer.Exit() +