From c1f360ede095badad3116bc782b0ede9f7ead572 Mon Sep 17 00:00:00 2001 From: James Frost Date: Fri, 22 Dec 2023 14:35:02 +0000 Subject: [PATCH] Take additional CLI arguments from CSET_ADDOPTS env var Fix test of CLI help --- src/CSET/__init__.py | 7 +++++-- tests/test_cli.py | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/CSET/__init__.py b/src/CSET/__init__.py index e78fbae4f..6e04bd9c6 100644 --- a/src/CSET/__init__.py +++ b/src/CSET/__init__.py @@ -16,6 +16,7 @@ import argparse import logging +import os import sys from importlib.metadata import version from pathlib import Path @@ -114,7 +115,8 @@ def main(): ) parser_cookbook.set_defaults(func=_cookbook_command) - args, unparsed_args = parser.parse_known_args() + cli_args = sys.argv[1:] + os.getenv("CSET_ADDOPTS", "").split() + args, unparsed_args = parser.parse_known_args(cli_args) # Setup logging. logging.captureWarnings(True) @@ -139,7 +141,8 @@ def main(): parser.print_usage() sys.exit(2) else: - parser.print_help() + parser.print_usage() + sys.exit(2) def _bake_command(args, unparsed_args): diff --git a/tests/test_cli.py b/tests/test_cli.py index b86dd76b3..2c1f49866 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -29,14 +29,15 @@ def test_command_line_help(): """Check that help commands work.""" subprocess.run(["cset", "--help"], check=True) - # Test verbose options. This is really just to up the coverage number. - subprocess.run(["cset", "-v"], check=True) - subprocess.run(["cset", "-vv"], check=True) subprocess.run(["cset", "--version"], check=True) # Gain coverage of __main__.py subprocess.run(["python3", "-m", "CSET", "-h"], check=True) + # Test verbose options. This is really just to up the coverage number. + subprocess.run(["cset", "-v"]) + subprocess.run(["cset", "-vv"]) + def test_recipe_execution(): """Test running CSET recipe from the command line."""