Skip to content

Commit ec50712

Browse files
author
Christophe Guerreiro
committed
spdx-diff: cli: Redirect print_diff text output to stderr
This change ensures that textual output from print_diff are properly separated from standard output, improving compatibility with tools and pipelines that rely on stdout for structured data or program output. Signed-off-by: Christophe Guerreiro <christophe.guerreiro@non.se.com>
1 parent 477a93a commit ec50712

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

src/spdx_diff/cli.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import logging
66
import pathlib
77
import re
8+
import sys
89
from argparse import ArgumentParser, ArgumentTypeError, BooleanOptionalAction
910
from collections import defaultdict
11+
from contextlib import redirect_stdout
1012
from datetime import datetime, timezone
1113
from typing import Any
1214

@@ -509,24 +511,26 @@ def main() -> None:
509511
pcfg_diff[2],
510512
)
511513

512-
# Print summary or full output
513-
if show_packages:
514-
print_diff(
515-
"Packages",
516-
*pkg_diff,
517-
)
518-
if show_kernel_config:
519-
print_diff(
520-
"Kernel Config",
521-
*cfg_diff,
522-
)
523-
if show_packageconfig:
524-
print_packageconfig_diff(
525-
*pcfg_light_diff,
526-
)
527-
528514
if args.format in ["json", "both"]:
529515
write_diff_to_json(pkg_diff, cfg_diff, pcfg_light_diff, args.output)
516+
# Print human readable information on stderr
517+
with redirect_stdout(sys.stderr):
518+
if show_packages:
519+
print_diff(
520+
"Packages",
521+
*pkg_diff,
522+
)
523+
if show_kernel_config:
524+
print_diff(
525+
"Kernel Config",
526+
*cfg_diff,
527+
)
528+
if show_packageconfig:
529+
print_packageconfig_diff(
530+
*pcfg_light_diff,
531+
)
532+
533+
530534

531535

532536
if __name__ == "__main__":

0 commit comments

Comments
 (0)