Skip to content

Commit

Permalink
Add "merge --input-file-list NAME ..." as a way to exceed CLI limits
Browse files Browse the repository at this point in the history
  • Loading branch information
jimklimov committed Jul 17, 2023
1 parent 5de8d19 commit af1a9a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Usage:
cyclonedx merge [options]
Options:
--input-file-list <input-file-list-file> A single text file with input BOM filenames (one per line).
--input-files <input-files> Input BOM filenames (separate filenames with a space).
--output-file <output-file> Output BOM filename, will write to stdout if no value provided.
--input-format <autodetect|json|protobuf|xml> Specify input file format.
Expand All @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion src/cyclonedx/Commands/MergeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Threading.Tasks;
using CycloneDX.Models;
using CycloneDX.Utils;
using System.IO;

namespace CycloneDX.Cli.Commands
{
Expand All @@ -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<string>("--input-file-list", "A single text file with input BOM filenames (one per line)."));
//TBD//subCommand.Add(new Option<string>("--input-file-list0", "A single text file with input BOM filenames (separated by 0x00 characters)."));
subCommand.Add(new Option<List<string>>("--input-files", "Input BOM filenames (separate filenames with a space)."));
subCommand.Add(new Option<string>("--output-file", "Output BOM filename, will write to stdout if no value provided."));
subCommand.Add(new Option<CycloneDXBomFormat>("--input-format", "Specify input file format."));
Expand Down Expand Up @@ -61,7 +64,12 @@ public static async Task<int> Merge(MergeCommandOptions options)
return (int)ExitCode.ParameterValidationError;
}

var inputBoms = await InputBoms(options.InputFiles, options.InputFormat, outputToConsole).ConfigureAwait(false);
List<string> InputFiles = (List<string>)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)
Expand Down
4 changes: 3 additions & 1 deletion src/cyclonedx/Commands/MergeCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace CycloneDX.Cli.Commands
{
public class MergeCommandOptions
{
public string InputFilesList { get; set; }
//TBD//public string InputFilesList0 { get; set; }
public IList<string> InputFiles { get; set; }
public string OutputFile { get; set; }
public CycloneDXBomFormat InputFormat { get; set; }
Expand All @@ -29,4 +31,4 @@ public class MergeCommandOptions
public string Name { get; set; }
public string Version { get; set; }
}
}
}

0 comments on commit af1a9a0

Please sign in to comment.