Skip to content

Commit 6fb9406

Browse files
committed
Add "merge --input-file-list NAME ..." as a way to exceed CLI limits
Signed-off-by: Jim Klimov <[email protected]>
1 parent 5de8d19 commit 6fb9406

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ Usage:
192192
cyclonedx merge [options]
193193
194194
Options:
195+
--input-file-list <input-file-list-file> A single text file with input BOM filenames (one per line).
195196
--input-files <input-files> Input BOM filenames (separate filenames with a space).
196197
--output-file <output-file> Output BOM filename, will write to stdout if no value provided.
197198
--input-format <autodetect|json|protobuf|xml> Specify input file format.
@@ -205,6 +206,11 @@ Options:
205206
Note: To perform a hierarchical merge all BOMs need the subject of the BOM
206207
described in the metadata component element.
207208

209+
The `--input-file-list` option can be useful if you have so many filenames to
210+
merge that your shell interpreter command-line limit is exceeded if you list
211+
them all as `--input-files`, or if your path names have spaces. If you specify
212+
both options, the effective file lists will be concatenated before merge.
213+
208214
### Examples
209215

210216
Merge two XML formatted BOMs:

src/cyclonedx/Commands/MergeCommand.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Threading.Tasks;
2323
using CycloneDX.Models;
2424
using CycloneDX.Utils;
25+
using System.IO;
2526

2627
namespace CycloneDX.Cli.Commands
2728
{
@@ -31,6 +32,8 @@ public static void Configure(RootCommand rootCommand)
3132
{
3233
Contract.Requires(rootCommand != null);
3334
var subCommand = new Command("merge", "Merge two or more BOMs");
35+
subCommand.Add(new Option<string>("--input-file-list", "A single text file with input BOM filenames (one per line)."));
36+
//TBD//subCommand.Add(new Option<string>("--input-file-list0", "A single text file with input BOM filenames (separated by 0x00 characters)."));
3437
subCommand.Add(new Option<List<string>>("--input-files", "Input BOM filenames (separate filenames with a space)."));
3538
subCommand.Add(new Option<string>("--output-file", "Output BOM filename, will write to stdout if no value provided."));
3639
subCommand.Add(new Option<CycloneDXBomFormat>("--input-format", "Specify input file format."));
@@ -61,7 +64,12 @@ public static async Task<int> Merge(MergeCommandOptions options)
6164
return (int)ExitCode.ParameterValidationError;
6265
}
6366

64-
var inputBoms = await InputBoms(options.InputFiles, options.InputFormat, outputToConsole).ConfigureAwait(false);
67+
List<string> InputFiles = (List<string>)options.InputFiles;
68+
if (options.InputFilesList != null)
69+
{
70+
InputFiles.AddRange(File.ReadAllLines(options.InputFilesList));
71+
}
72+
var inputBoms = await InputBoms(InputFiles, options.InputFormat, outputToConsole).ConfigureAwait(false);
6573

6674
Component bomSubject = null;
6775
if (options.Group != null || options.Name != null || options.Version != null)

src/cyclonedx/Commands/MergeCommandOptions.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace CycloneDX.Cli.Commands
2020
{
2121
public class MergeCommandOptions
2222
{
23+
public string InputFilesList { get; set; }
24+
//TBD//public string InputFilesList0 { get; set; }
2325
public IList<string> InputFiles { get; set; }
2426
public string OutputFile { get; set; }
2527
public CycloneDXBomFormat InputFormat { get; set; }
@@ -29,4 +31,4 @@ public class MergeCommandOptions
2931
public string Name { get; set; }
3032
public string Version { get; set; }
3133
}
32-
}
34+
}

0 commit comments

Comments
 (0)