Skip to content

Commit

Permalink
Pass all args after <innercmd> to inner command (#56)
Browse files Browse the repository at this point in the history
* Pass all args after <innercmd> to inner command

Fixes: #51

* Do not suggest jq, output is no longer json

* Fixup: remove now-unused arguments for clearer name
  • Loading branch information
asmacdo authored Jun 7, 2024
1 parent f74d1e7 commit 84f08fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
10 changes: 6 additions & 4 deletions src/duct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -405,7 +407,7 @@ def execute(args):

report = Report(
args.command,
args.arguments,
args.inner_args,
session_id,
formatted_output_prefix,
process,
Expand Down
16 changes: 8 additions & 8 deletions test/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 84f08fd

Please sign in to comment.