Skip to content

Commit

Permalink
Take additional CLI arguments from CSET_ADDOPTS env var
Browse files Browse the repository at this point in the history
Fix test of CLI help
  • Loading branch information
jfrost-mo committed Dec 22, 2023
1 parent f847f69 commit c1f360e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/CSET/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import argparse
import logging
import os
import sys
from importlib.metadata import version
from pathlib import Path
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit c1f360e

Please sign in to comment.