Skip to content

Commit 96a0f2c

Browse files
Add output-file option
1 parent 6120e6b commit 96a0f2c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/pyhf/cli/utils.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""The pyhf utils CLI subcommand."""
22
import logging
3+
from pathlib import Path
34

45
import click
56
from pyhf import utils
@@ -13,5 +14,21 @@ def cli():
1314

1415

1516
@cli.command()
16-
def debug():
17-
click.echo(utils.debug_info())
17+
@click.option(
18+
"-o",
19+
"--output-file",
20+
help="The location of the output file. If not specified, prints to screen.",
21+
default=None,
22+
)
23+
def debug(output_file):
24+
debug_info = utils.debug_info()
25+
26+
if output_file:
27+
output_file = Path(output_file)
28+
output_file.parent.mkdir(parents=True, exist_ok=True)
29+
30+
with open(output_file, "w+", encoding="utf-8") as out_file:
31+
out_file.write(debug_info)
32+
log.debug(f"Written to {output_file}")
33+
else:
34+
click.echo(debug_info)

0 commit comments

Comments
 (0)