diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 14f927b..da6b03e 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,7 +1,7 @@ true - 11.0 + 12.0 enable true true diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 1abc525..ae44162 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -20,8 +20,8 @@ - - + + diff --git a/src/GenerateNotice/Program.cs b/src/GenerateNotice/Program.cs index 123e3ba..3504315 100644 --- a/src/GenerateNotice/Program.cs +++ b/src/GenerateNotice/Program.cs @@ -32,55 +32,64 @@ public static async Task Main(string[] args) var rootCommand = new RootCommand("Third-party notice generator"); - var assetFilesOption = new Option>("--asset-files", "One or more paths to project.assets.json file(s).") + var assetFilesOption = new Option>("--asset-files") { + Description = "One or more paths to project.assets.json file(s).", Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true, - IsRequired = false }; - var npmListJsonFilesOption = new Option>("--npm-list-json-files", "One or more paths to files generated by the 'npm list -a --json' command.") + var npmListJsonFilesOption = new Option>("--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("--output-file", "Path where the generated NOTICE file will be saved.") + var outputOption = new Option("--output-file") { - IsRequired = true + Description = "Path where the generated NOTICE file will be saved.", + Required = true }; - var preambleFileOption = new Option("--preamble-file", "Path to a text file whose contents will be included at the top of the generated NOTICE file.") + var preambleFileOption = new Option("--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("--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("--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("--retry-count", $"Number of retries for each API call. The default is {DefaultRetryCount}.") + var retryCountOption = new Option("--retry-count") { - IsRequired = false + Description = $"Number of retries for each API call. The default is {DefaultRetryCount}." }; - var timeoutOptionSecondsOption = new Option("--timeout-seconds", $"Timeout in seconds for each API call. The default is {DefaultTimeoutSeconds}.") + var timeoutOptionSecondsOption = new Option("--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(), @@ -92,10 +101,10 @@ public static async Task 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(