Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add automatic detection of output format from filename #891

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
}
}