Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Deterministic>true</Deterministic>
<LangVersion>11.0</LangVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<PackageVersion Include="NuGet.Packaging" Version="6.11.1" />
<PackageVersion Include="Polly" Version="8.6.4" />
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.3" />
<PackageVersion Include="System.CommandLine.Hosting" Version="0.4.0-alpha.25306.1" />
<PackageVersion Include="System.Formats.Asn1" Version="6.0.1" />
<PackageVersion Include="System.Net.Http.Json" Version="8.0.1" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
Expand Down
59 changes: 34 additions & 25 deletions src/GenerateNotice/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,55 +32,64 @@ public static async Task<int> Main(string[] args)

var rootCommand = new RootCommand("Third-party notice generator");

var assetFilesOption = new Option<List<string>>("--asset-files", "One or more paths to project.assets.json file(s).")
var assetFilesOption = new Option<List<string>>("--asset-files")
{
Description = "One or more paths to project.assets.json file(s).",
Arity = ArgumentArity.ZeroOrMore,
AllowMultipleArgumentsPerToken = true,
IsRequired = false
};

var npmListJsonFilesOption = new Option<List<string>>("--npm-list-json-files", "One or more paths to files generated by the 'npm list -a --json' command.")
var npmListJsonFilesOption = new Option<List<string>>("--npm-list-json-files")
{
Description = "One or more paths to files generated by the 'npm list -a --json' command.",
Arity = ArgumentArity.ZeroOrMore,
AllowMultipleArgumentsPerToken = true,
IsRequired = false
};

var outputOption = new Option<string>("--output-file", "Path where the generated NOTICE file will be saved.")
var outputOption = new Option<string>("--output-file")
{
IsRequired = true
Description = "Path where the generated NOTICE file will be saved.",
Required = true
};

var preambleFileOption = new Option<string>("--preamble-file", "Path to a text file whose contents will be included at the top of the generated NOTICE file.")
var preambleFileOption = new Option<string>("--preamble-file")
{
IsRequired = false
Description = "Path to a text file whose contents will be included at the top of the generated NOTICE file."
};

var batchSizeOption = new Option<int?>("--batch-size", $"Number of libraries to submit on a single API call. Batches will be submitted sequentially. The default is {DefaultBatchSize}.")
var batchSizeOption = new Option<int?>("--batch-size")
{
IsRequired = false
Description = $"Number of libraries to submit on a single API call. Batches will be submitted sequentially. The default is {DefaultBatchSize}."
};

var retryCountOption = new Option<int?>("--retry-count", $"Number of retries for each API call. The default is {DefaultRetryCount}.")
var retryCountOption = new Option<int?>("--retry-count")
{
IsRequired = false
Description = $"Number of retries for each API call. The default is {DefaultRetryCount}."
};

var timeoutOptionSecondsOption = new Option<int?>("--timeout-seconds", $"Timeout in seconds for each API call. The default is {DefaultTimeoutSeconds}.")
var timeoutOptionSecondsOption = new Option<int?>("--timeout-seconds")
{
IsRequired = false
Description = $"Timeout in seconds for each API call. The default is {DefaultTimeoutSeconds}."
};

rootCommand.AddOption(assetFilesOption);
rootCommand.AddOption(npmListJsonFilesOption);
rootCommand.AddOption(outputOption);
rootCommand.AddOption(preambleFileOption);
rootCommand.AddOption(batchSizeOption);
rootCommand.AddOption(retryCountOption);
rootCommand.AddOption(timeoutOptionSecondsOption);
rootCommand.Add(assetFilesOption);
rootCommand.Add(npmListJsonFilesOption);
rootCommand.Add(outputOption);
rootCommand.Add(preambleFileOption);
rootCommand.Add(batchSizeOption);
rootCommand.Add(retryCountOption);
rootCommand.Add(timeoutOptionSecondsOption);

rootCommand.SetHandler((assetFiles, npmListJsonFiles, outputFile, preambleFile, batchSize, retryCount, timeoutSeconds) =>
rootCommand.SetAction(async (ParseResult parseResult, CancellationToken cancel) =>
{
var assetFiles = parseResult.GetValue(assetFilesOption) ?? [];
var npmListJsonFiles = parseResult.GetValue(npmListJsonFilesOption) ?? [];
var outputFile = parseResult.GetValue(outputOption)!; // Required = true guarantees a non-null value
var preambleFile = parseResult.GetValue(preambleFileOption);
var batchSize = parseResult.GetValue(batchSizeOption);
var retryCount = parseResult.GetValue(retryCountOption);
var timeoutSeconds = parseResult.GetValue(timeoutOptionSecondsOption);

var arguments = new ToolArguments
(
AssetFiles: assetFiles.Select(ResolvePath).ToImmutableArray(),
Expand All @@ -92,10 +101,10 @@ public static async Task<int> Main(string[] args)
Timeout: TimeSpan.FromSeconds(timeoutSeconds ?? DefaultTimeoutSeconds)
);

return MainInternal(arguments);
}, assetFilesOption, npmListJsonFilesOption, outputOption, preambleFileOption, batchSizeOption, retryCountOption, timeoutOptionSecondsOption);
return await MainInternal(arguments);
});

return await rootCommand.InvokeAsync(args);
return await rootCommand.Parse(args).InvokeAsync();
}

public record ToolArguments(
Expand Down
Loading