Skip to content

Commit ff55606

Browse files
committed
rimport: Fix help on older Pythons.
1 parent bd02bb3 commit ff55606

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

rimport

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def build_parser() -> argparse.ArgumentParser:
3737
argparse.ArgumentParser: Configured parser ready to parse command-line arguments.
3838
"""
3939
parser = argparse.ArgumentParser(
40-
description="Copy files from CESM inputdata directory to a publishing directory."
40+
description="Copy files from CESM inputdata directory to a publishing directory.",
41+
add_help=False, # Disable automatic help to add custom -help flag
4142
)
4243

4344
# Mutually exclusive: -file or -list (one required)
@@ -72,8 +73,14 @@ def build_parser() -> argparse.ArgumentParser:
7273
),
7374
)
7475

75-
# Provide -help to mirror legacy behavior
76-
parser.add_argument("-help", action="help", help=argparse.SUPPRESS)
76+
# Provide -help to mirror legacy behavior (in addition to -h and --help)
77+
parser.add_argument(
78+
"-h",
79+
"--help",
80+
"-help",
81+
action="help",
82+
help="Show this help message and exit",
83+
)
7784

7885
return parser
7986

tests/rimport/test_cmdline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ def test_help_flag_shows_help(self, rimport_script, help_flag):
264264
# Help should exit with code 0
265265
assert result.returncode == 0
266266
assert "usage:" in result.stdout
267-
assert "options:" in result.stdout
267+
# Python 3.10+ uses "options:", earlier versions use "optional arguments:"
268+
assert "options:" in result.stdout or "optional arguments:" in result.stdout
268269

269270
def test_list_with_comments_and_blanks(self, rimport_script, test_env, rimport_env):
270271
"""Test that list file with comments and blank lines works correctly."""

0 commit comments

Comments
 (0)