Skip to content

Commit

Permalink
feat: Detect output format from output filename if provided
Browse files Browse the repository at this point in the history
- Implemented logic to detect the output format from the output filename extension.
- If `-fn` is set but `--json` or `--bom-format` are not set, the format is determined based on the file extension.
- Supported extensions: .xml, .json, .proto, .pb, .bin.
- Explicit parameters `--json` or `--bom-format` take precedence if set.


Signed-off-by: Michael Tsfoni <[email protected]>
  • Loading branch information
mtsfoni authored Jul 1, 2024
1 parent 2a3fab2 commit 993cccc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions CycloneDX/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public Runner() : this(null, null, null, null, null, null, null, null) { }
public async Task<int> HandleCommandAsync(RunOptions options)
{
options.outputDirectory ??= fileSystem.Directory.GetCurrentDirectory();
SetOutputFormatFromFilename(options);

string outputDirectory = options.outputDirectory;
string SolutionOrProjectFile = options.SolutionOrProjectFile;
string framework = options.framework;
Expand Down Expand Up @@ -511,5 +513,29 @@ internal static void AddMetadataTool(Bom bom)
}
}

private void SetOutputFormatFromFilename(RunOptions options)
{
if (!string.IsNullOrEmpty(options.outputFilename))
{
var extension = Path.GetExtension(options.outputFilename).ToLowerInvariant();
switch (extension)
{
case ".xml":
options.json = false;
break;
case ".json":
options.json = true;
break;
case ".proto":
case ".pb":
case ".bin":
// Add handling for other future formats here
break;
default:
Console.Error.WriteLine($"Unsupported file extension '{extension}' for output filename");
break;
}
}
}
}
}

0 comments on commit 993cccc

Please sign in to comment.