Skip to content

Commit

Permalink
MergeCommand: implement support for --input-files-list0
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Klimov <jimklimov@gmail.com>
  • Loading branch information
jimklimov committed Jul 19, 2023
1 parent fdac250 commit 1cc6622
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Usage:
Options:
--input-files <input-files> Input BOM filenames (separate filenames with a space).
--input-files-list <input-files-list-files> One or more text file(s) with input BOM filenames (one per line).
--input-files-list0 <input-files-list-files> One or more text-like file(s) with input BOM filenames (separated by 0x00 characters).
--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.
--output-format <autodetect|json|protobuf|xml> Specify output file format.
Expand All @@ -208,8 +209,20 @@ described in the metadata component element.

The `--input-files-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.
them all as `--input-files`, or if your path names have spaces.

The related `--input-files-list0` is intended for lists prepared by commands
like `find ... -print0` and makes sense on filesystems where carriage-return
and/or line-feed characters may validly be present in a path name component.
Note: behavior with multi-byte encodings (Unicode family) where a 0x00 byte
can be part of a character may be undefined.

If you specify several of these options, the effective file lists will be
concatenated before the actual merge (first the individual `--input-files`,
then the contents of `--input-files-list`, and finally the contents of
`--input-files-list0`). If you have a document crafted to describe the root
of your product hierarchy tree, it is recommended to list it as the first
of individual `--input-files` (or otherwise on first line among used lists).

### Examples

Expand Down
15 changes: 14 additions & 1 deletion src/cyclonedx/Commands/MergeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void Configure(RootCommand rootCommand)
var subCommand = new Command("merge", "Merge two or more BOMs");
subCommand.Add(new Option<List<string>>("--input-files", "Input BOM filenames (separate filenames with a space)."));
subCommand.Add(new Option<List<string>>("--input-files-list", "One or more text file(s) with input BOM filenames (one per line)."));
//TBD//subCommand.Add(new Option<List<string>>("--input-files-list0", "One or more text file(s) with input BOM filenames (separated by 0x00 characters)."));
subCommand.Add(new Option<List<string>>("--input-files-list0", "One or more text-like file(s) with input BOM filenames (separated by 0x00 characters)."));
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."));
subCommand.Add(new Option<CycloneDXBomFormat>("--output-format", "Specify output file format."));
Expand Down Expand Up @@ -86,6 +86,19 @@ public static async Task<int> Merge(MergeCommandOptions options)
Console.WriteLine($"Got " + lines.Length + " entries from " + OneInputFileList);
}
}

if (options.InputFilesList0 != null)
{
ImmutableList<string> InputFilesList0 = options.InputFilesList0.ToImmutableList();
Console.WriteLine($"Got " + InputFilesList0.Count + " file(s) with NUL-separated actual input file names: ['" + string.Join("', '", InputFilesList0) + "']");
foreach (string OneInputFileList in InputFilesList0) {
Console.WriteLine($"Adding to input file list from " + OneInputFileList);
string[] lines = File.ReadAllText(OneInputFileList).Split('\0');
InputFiles.AddRange(lines);
Console.WriteLine($"Got " + lines.Length + " entries from " + OneInputFileList);
}
}

// TODO: Consider InputFiles.Distinct().ToList() -
// but that requires C# 3.0 for extension method support,
// and .NET 3.5 to get the LINQ Enumerable class.
Expand Down
2 changes: 1 addition & 1 deletion src/cyclonedx/Commands/MergeCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class MergeCommandOptions
{
public IList<string> InputFiles { get; set; }
public IList<string> InputFilesList { get; set; }
//TBD//public IList<string> InputFilesList0 { get; set; }
public IList<string> InputFilesList0 { get; set; }
public string OutputFile { get; set; }
public CycloneDXBomFormat InputFormat { get; set; }
public CycloneDXBomFormat OutputFormat { get; set; }
Expand Down

0 comments on commit 1cc6622

Please sign in to comment.