Skip to contentSkip to conversation

utils/generate-cyclonedx: fix detecting of tty

PATCH In review Heiko Thiery 2 participants 2 messages Feb 28, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils/generate-cyclonedx: fix detecting of tty

Check if the script shall read from stdin if data is piped into. Otherwise read from the input file or if not specified print usage and exit.

---
 utils/generate-cyclonedx | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
utils/generate-cyclonedx +8 -2
index 993d7154ef..365c2b06ea 100755
@@ -273,13 +273,19 @@ def main():
                 Example usage: make show-info | utils/generate-cyclonedx.py | jq > sbom.json
             '''
         )
-    parser.add_argument("-i", "--in-file", nargs="?", type=argparse.FileType("r"), default=sys.stdin)
-    parser.add_argument("-o", "--out-file", nargs="?", type=argparse.FileType("w"), default=sys.stdout)
+    parser.add_argument("-i", "--in-file", nargs="?", type=argparse.FileType("r"),
+                        default=(None if sys.stdin.isatty() else sys.stdin))
+    parser.add_argument("-o", "--out-file", nargs="?", type=argparse.FileType("w"),
+                        default=sys.stdout)
     parser.add_argument("--virtual", default=False, action='store_true',
                         help="This option includes virtual packages to the CycloneDX output")
 
     args = parser.parse_args()
 
+    if args.in_file is None:
+        parser.print_help()
+        sys.exit(1)
+
     show_info_dict = json.load(args.in_file)
 
     # Remove rootfs and virtual packages if not explicitly included
Signature · 6 lines
2.39.5

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Heiko" == Heiko Thiery <[email protected]> writes:

Check if the script shall read from stdin if data is piped into. Otherwise read from the input file or if not specified print usage and exit.

Nice little UI improvement.

Committed, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot