From e6ced61d4667d4e3fef8b33ccca51b5f466baf32 Mon Sep 17 00:00:00 2001 From: "Carl A. B. Pearson" Date: Wed, 11 Dec 2024 12:18:21 -0500 Subject: [PATCH] modify approach to handling help --- flepimop/gempyor_pkg/src/gempyor/cli.py | 2 +- flepimop/gempyor_pkg/src/gempyor/shared_cli.py | 4 +++- flepimop/gempyor_pkg/src/gempyor/simulate.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/cli.py b/flepimop/gempyor_pkg/src/gempyor/cli.py index 43bad34fc..f7bda4231 100644 --- a/flepimop/gempyor_pkg/src/gempyor/cli.py +++ b/flepimop/gempyor_pkg/src/gempyor/cli.py @@ -21,7 +21,7 @@ # add some basic commands to the CLI -@cli.command(params=[config_files_argument] + list(config_file_options.values())) +@cli.command(params=[config_files_argument] + list(config_file_options.values()), context_settings=dict(help_option_names = ['-h', '--help'])) @click.pass_context def patch(ctx: click.Context = mock_context, **kwargs) -> None: """Merge configuration files diff --git a/flepimop/gempyor_pkg/src/gempyor/shared_cli.py b/flepimop/gempyor_pkg/src/gempyor/shared_cli.py index f98449e61..d73a2c5f1 100644 --- a/flepimop/gempyor_pkg/src/gempyor/shared_cli.py +++ b/flepimop/gempyor_pkg/src/gempyor/shared_cli.py @@ -222,7 +222,9 @@ def _parse_option(param: click.Parameter, value: Any) -> Any: config_src = [] if len(found_configs) != 1: if not found_configs: - raise ValueError(f"No config files provided.") + click.echo("No configuration provided! See help for required usage:\n") + click.echo(ctx.get_help()) + ctx.exit() else: error_dict = {k: kwargs[k] for k in found_configs} raise ValueError( diff --git a/flepimop/gempyor_pkg/src/gempyor/simulate.py b/flepimop/gempyor_pkg/src/gempyor/simulate.py index e8602818d..34499f6be 100644 --- a/flepimop/gempyor_pkg/src/gempyor/simulate.py +++ b/flepimop/gempyor_pkg/src/gempyor/simulate.py @@ -300,7 +300,8 @@ def simulate( @cli.command( - name="simulate", params=[config_files_argument] + list(config_file_options.values()) + name="simulate", params=[config_files_argument] + list(config_file_options.values()), + context_settings=dict(help_option_names=["-h", "--help"]) ) @pass_context def _click_simulate(ctx: Context, **kwargs) -> int: