From 4751b49b2f324b4b2cc976e5fcc7a2ebe0e99c82 Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Tue, 24 Mar 2026 13:56:17 -0500 Subject: [PATCH 1/3] feat: invoker accepts 'afdko -u' or 'afdko -u ' --- python/afdko/invoker.py | 14 +++++++++----- tests/invoker_test.py | 23 +++++++++++++++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/python/afdko/invoker.py b/python/afdko/invoker.py index a14e4649b..803669d2a 100644 --- a/python/afdko/invoker.py +++ b/python/afdko/invoker.py @@ -8,7 +8,6 @@ import sys from typing import NoReturn - # Complete command registry with abbreviations # Format: name -> (module:function, description, category) # Categories: 'primary', 'secondary', 'plot' @@ -206,6 +205,9 @@ def dispatch_command(cmd: str) -> NoReturn: def main() -> NoReturn: """Main entry point for the unified afdko command.""" + help_flags = ('-h', '--help', 'help') + pre_command_forward_flags = help_flags + ('-u',) + # No subcommand provided if len(sys.argv) < 2: print_help('primary') @@ -225,20 +227,22 @@ def main() -> NoReturn: sys.exit(0) # Help requested - if subcmd in ('-h', '--help', 'help'): - # Check for command name after -h + if subcmd in pre_command_forward_flags: + # Check for command name after -h/-u if len(sys.argv) > 2: arg = sys.argv[2] # afdko -h -> afdko -h + # afdko -u -> afdko -u # Check if it's a valid command if arg in ALL_COMMANDS: - sys.argv = ['afdko', arg, '-h'] + forwarded_flag = '-h' if subcmd in help_flags else subcmd + sys.argv = ['afdko', arg, forwarded_flag] dispatch_command(arg) else: print(f"Error: Unknown command '{arg}'", file=sys.stderr) print("Run 'afdko --help' for usage.", file=sys.stderr) sys.exit(1) - else: + elif subcmd in help_flags: print_help('primary') sys.exit(0) diff --git a/tests/invoker_test.py b/tests/invoker_test.py index 5a7d83d16..cf8d0702e 100644 --- a/tests/invoker_test.py +++ b/tests/invoker_test.py @@ -8,9 +8,9 @@ - Commands are correctly dispatched to their implementations """ -import pytest import subprocess -import sys + +import pytest class TestHelpSystem: @@ -92,6 +92,25 @@ def test_help_command_specific_unknown(self): assert result.returncode == 1 assert "Unknown command 'invalidcmd'" in result.stderr + @pytest.mark.parametrize('command', ['tx', 'makeotf']) + def test_usage_command_specific_forwarding(self, command): + """afdko -u forwards to command usage output.""" + reordered = subprocess.run(['afdko', '-u', command], + capture_output=True, text=True) + direct = subprocess.run(['afdko', command, '-u'], + capture_output=True, text=True) + + assert reordered.returncode == direct.returncode, ( + f"afdko -u {command} returned {reordered.returncode}, expected " + f"the same exit code as afdko {command} -u ({direct.returncode})." + ) + assert reordered.stdout == direct.stdout, ( + f"afdko -u {command} stdout did not match afdko {command} -u." + ) + assert reordered.stderr == direct.stderr, ( + f"afdko -u {command} stderr did not match afdko {command} -u." + ) + class TestErrorHandling: """Test error handling for invalid commands.""" From 201bea52d3ec2d71a462d2cd4630a3d1fdda57fd Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Tue, 24 Mar 2026 18:56:05 -0500 Subject: [PATCH 2/3] "-u" in the wrong order is changed to "-h" --- python/afdko/invoker.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/python/afdko/invoker.py b/python/afdko/invoker.py index 803669d2a..44038b458 100644 --- a/python/afdko/invoker.py +++ b/python/afdko/invoker.py @@ -205,9 +205,6 @@ def dispatch_command(cmd: str) -> NoReturn: def main() -> NoReturn: """Main entry point for the unified afdko command.""" - help_flags = ('-h', '--help', 'help') - pre_command_forward_flags = help_flags + ('-u',) - # No subcommand provided if len(sys.argv) < 2: print_help('primary') @@ -227,22 +224,21 @@ def main() -> NoReturn: sys.exit(0) # Help requested - if subcmd in pre_command_forward_flags: + if subcmd in ('-h', '--help', 'help', '-u'): # Check for command name after -h/-u if len(sys.argv) > 2: arg = sys.argv[2] # afdko -h -> afdko -h - # afdko -u -> afdko -u + # afdko -u -> afdko -h # Check if it's a valid command if arg in ALL_COMMANDS: - forwarded_flag = '-h' if subcmd in help_flags else subcmd - sys.argv = ['afdko', arg, forwarded_flag] + sys.argv = ['afdko', arg, '-h'] dispatch_command(arg) else: print(f"Error: Unknown command '{arg}'", file=sys.stderr) print("Run 'afdko --help' for usage.", file=sys.stderr) sys.exit(1) - elif subcmd in help_flags: + else: print_help('primary') sys.exit(0) From 2077acf014cdfbc6731d9eba841358c358c106f1 Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Tue, 24 Mar 2026 19:11:21 -0500 Subject: [PATCH 3/3] Remove unneeded test. --- tests/invoker_test.py | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/tests/invoker_test.py b/tests/invoker_test.py index cf8d0702e..cb51ebb7d 100644 --- a/tests/invoker_test.py +++ b/tests/invoker_test.py @@ -8,9 +8,8 @@ - Commands are correctly dispatched to their implementations """ -import subprocess - import pytest +import subprocess class TestHelpSystem: @@ -92,25 +91,6 @@ def test_help_command_specific_unknown(self): assert result.returncode == 1 assert "Unknown command 'invalidcmd'" in result.stderr - @pytest.mark.parametrize('command', ['tx', 'makeotf']) - def test_usage_command_specific_forwarding(self, command): - """afdko -u forwards to command usage output.""" - reordered = subprocess.run(['afdko', '-u', command], - capture_output=True, text=True) - direct = subprocess.run(['afdko', command, '-u'], - capture_output=True, text=True) - - assert reordered.returncode == direct.returncode, ( - f"afdko -u {command} returned {reordered.returncode}, expected " - f"the same exit code as afdko {command} -u ({direct.returncode})." - ) - assert reordered.stdout == direct.stdout, ( - f"afdko -u {command} stdout did not match afdko {command} -u." - ) - assert reordered.stderr == direct.stderr, ( - f"afdko -u {command} stderr did not match afdko {command} -u." - ) - class TestErrorHandling: """Test error handling for invalid commands."""