From af1a9a0f7d002be20da43f24b392327bd66b1ce8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 17 Jul 2023 17:33:17 +0200 Subject: [PATCH] Add "merge --input-file-list NAME ..." as a way to exceed CLI limits --- README.md | 6 ++++++ src/cyclonedx/Commands/MergeCommand.cs | 10 +++++++++- src/cyclonedx/Commands/MergeCommandOptions.cs | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cd59de2..9e6f4c7 100755 --- a/README.md +++ b/README.md @@ -192,6 +192,7 @@ Usage: cyclonedx merge [options] Options: + --input-file-list A single text file with input BOM filenames (one per line). --input-files Input BOM filenames (separate filenames with a space). --output-file Output BOM filename, will write to stdout if no value provided. --input-format Specify input file format. @@ -205,6 +206,11 @@ Options: Note: To perform a hierarchical merge all BOMs need the subject of the BOM described in the metadata component element. +The `--input-file-list` option can be useful if you have so many filenames to +merge that your shell interpreter command-line limit is exceeded if you list +them all as `--input-files`, or if your path names have spaces. If you specify +both options, the effective file lists will be concatenated before merge. + ### Examples Merge two XML formatted BOMs: diff --git a/src/cyclonedx/Commands/MergeCommand.cs b/src/cyclonedx/Commands/MergeCommand.cs index 5c150d5..a88b011 100644 --- a/src/cyclonedx/Commands/MergeCommand.cs +++ b/src/cyclonedx/Commands/MergeCommand.cs @@ -22,6 +22,7 @@ using System.Threading.Tasks; using CycloneDX.Models; using CycloneDX.Utils; +using System.IO; namespace CycloneDX.Cli.Commands { @@ -31,6 +32,8 @@ public static void Configure(RootCommand rootCommand) { Contract.Requires(rootCommand != null); var subCommand = new Command("merge", "Merge two or more BOMs"); + subCommand.Add(new Option("--input-file-list", "A single text file with input BOM filenames (one per line).")); + //TBD//subCommand.Add(new Option("--input-file-list0", "A single text file with input BOM filenames (separated by 0x00 characters).")); subCommand.Add(new Option>("--input-files", "Input BOM filenames (separate filenames with a space).")); subCommand.Add(new Option("--output-file", "Output BOM filename, will write to stdout if no value provided.")); subCommand.Add(new Option("--input-format", "Specify input file format.")); @@ -61,7 +64,12 @@ public static async Task Merge(MergeCommandOptions options) return (int)ExitCode.ParameterValidationError; } - var inputBoms = await InputBoms(options.InputFiles, options.InputFormat, outputToConsole).ConfigureAwait(false); + List InputFiles = (List)options.InputFiles; + if (options.InputFilesList != null) + { + InputFiles.AddRange(File.ReadAllLines(options.InputFilesList)); + } + var inputBoms = await InputBoms(InputFiles, options.InputFormat, outputToConsole).ConfigureAwait(false); Component bomSubject = null; if (options.Group != null || options.Name != null || options.Version != null) diff --git a/src/cyclonedx/Commands/MergeCommandOptions.cs b/src/cyclonedx/Commands/MergeCommandOptions.cs index f3078c4..71df950 100644 --- a/src/cyclonedx/Commands/MergeCommandOptions.cs +++ b/src/cyclonedx/Commands/MergeCommandOptions.cs @@ -20,6 +20,8 @@ namespace CycloneDX.Cli.Commands { public class MergeCommandOptions { + public string InputFilesList { get; set; } + //TBD//public string InputFilesList0 { get; set; } public IList InputFiles { get; set; } public string OutputFile { get; set; } public CycloneDXBomFormat InputFormat { get; set; } @@ -29,4 +31,4 @@ public class MergeCommandOptions public string Name { get; set; } public string Version { get; set; } } -} \ No newline at end of file +}