From 84f08fdd7f7fb55f464720e0e41b0d3e7d7b7027 Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Fri, 7 Jun 2024 11:44:40 -0500 Subject: [PATCH] Pass all args after to inner command (#56) * Pass all args after to inner command Fixes: https://github.com/con/duct/issues/51 * Do not suggest jq, output is no longer json * Fixup: remove now-unused arguments for clearer name --- README.md | 2 +- src/duct.py | 10 ++++++---- test/test_execution.py | 16 ++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1f80e1a2..c29b0b32 100644 --- a/README.md +++ b/README.md @@ -65,5 +65,5 @@ options: --memory-size MEMORY_SIZE Amount of memory to allocate in MB. -duct --report-interval 4 -- ./test_script.py --duration 12 --cpu-load 50000 --memory-size 50 | jq +duct --report-interval 4 ./test_script.py --duration 12 --cpu-load 50000 --memory-size 50 ``` diff --git a/src/duct.py b/src/duct.py index fb8f1826..b98a0a7b 100755 --- a/src/duct.py +++ b/src/duct.py @@ -213,7 +213,9 @@ def create_and_parse_args(): formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument("command", help="The command to execute.") - parser.add_argument("arguments", nargs="*", help="Arguments for the command.") + parser.add_argument( + "inner_args", nargs=argparse.REMAINDER, help="Arguments for the command." + ) parser.add_argument( "-p", "--output-prefix", @@ -389,11 +391,11 @@ def execute(args): else: stderr_file = stderr - full_command = " ".join([str(args.command)] + args.arguments) + full_command = " ".join([str(args.command)] + args.inner_args) print(f"{Colors.OKCYAN}duct is executing {full_command}...") print(f"Log files will be written to {formatted_output_prefix}{Colors.ENDC}") process = subprocess.Popen( - [str(args.command)] + args.arguments, + [str(args.command)] + args.inner_args, stdout=stdout_file, stderr=stderr_file, preexec_fn=os.setsid, @@ -405,7 +407,7 @@ def execute(args): report = Report( args.command, - args.arguments, + args.inner_args, session_id, formatted_output_prefix, process, diff --git a/test/test_execution.py b/test/test_execution.py index c3db957d..24264a6b 100644 --- a/test/test_execution.py +++ b/test/test_execution.py @@ -16,7 +16,7 @@ def temp_output_dir(tmp_path): def test_sanity_green(temp_output_dir): args = argparse.Namespace( command="echo", - arguments=["hello", "world"], + inner_args=["hello", "world"], output_prefix=temp_output_dir, sample_interval=1.0, report_interval=60.0, @@ -33,7 +33,7 @@ def test_sanity_green(temp_output_dir): def test_sanity_red(temp_output_dir): args = argparse.Namespace( command="false", - arguments=[], + inner_args=[], output_prefix=temp_output_dir, sample_interval=1.0, report_interval=60.0, @@ -56,7 +56,7 @@ def test_sanity_red(temp_output_dir): def test_outputs_full(temp_output_dir): args = argparse.Namespace( command="./test_script.py", - arguments=["--duration", "1"], + inner_args=["--duration", "1"], output_prefix=temp_output_dir, sample_interval=0.01, report_interval=0.1, @@ -72,7 +72,7 @@ def test_outputs_full(temp_output_dir): def test_outputs_passthrough(temp_output_dir): args = argparse.Namespace( command="./test_script.py", - arguments=["--duration", "1"], + inner_args=["--duration", "1"], output_prefix=temp_output_dir, sample_interval=0.01, report_interval=0.1, @@ -90,7 +90,7 @@ def test_outputs_passthrough(temp_output_dir): def test_outputs_capture(temp_output_dir): args = argparse.Namespace( command="./test_script.py", - arguments=["--duration", "1"], + inner_args=["--duration", "1"], output_prefix=temp_output_dir, sample_interval=0.01, report_interval=0.1, @@ -108,7 +108,7 @@ def test_outputs_capture(temp_output_dir): def test_outputs_none(temp_output_dir): args = argparse.Namespace( command="./test_script.py", - arguments=["--duration", "1"], + inner_args=["--duration", "1"], output_prefix=temp_output_dir, sample_interval=0.01, report_interval=0.1, @@ -129,7 +129,7 @@ def test_outputs_none(temp_output_dir): def test_exit_before_first_sample(temp_output_dir): args = argparse.Namespace( command="ls", - arguments=[], + inner_args=[], output_prefix=temp_output_dir, sample_interval=0.1, report_interval=0.1, @@ -147,7 +147,7 @@ def test_exit_before_first_sample(temp_output_dir): def test_run_less_than_report_interval(temp_output_dir): args = argparse.Namespace( command="sleep", - arguments=["0.01"], + inner_args=["0.01"], output_prefix=temp_output_dir, sample_interval=0.001, report_interval=0.1,