Skip to content

System.CommandLine update #8702

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

Merged
merged 4 commits into from
Apr 14, 2025
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
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<Sha>1df7df81ac783e63aa7fbccb0232ad20fb128b15</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.25071.2">
<Dependency Name="System.CommandLine" Version="2.0.0-beta5.25208.1">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>3bbb940ceeb3254790899d751a8d418348563d40</Sha>
<Sha>48bd86bdcd926a194e1581a60d820d12a64ef3c6</Sha>
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PropertyGroup>
<!-- Non-maestro versions -->
<SystemFormatsAsn1Version>9.0.0</SystemFormatsAsn1Version>
<SystemCommandLinePackageVersion>2.0.0-beta4.25071.2</SystemCommandLinePackageVersion>
<SystemCommandLinePackageVersion>2.0.0-beta5.25208.1</SystemCommandLinePackageVersion>
<MicrosoftExtensionsLoggingPackageVersion>9.0.3</MicrosoftExtensionsLoggingPackageVersion>
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>9.0.3</MicrosoftExtensionsLoggingAbstractionsPackageVersion>
<MicrosoftExtensionsLoggingConsolePackageVersion>9.0.3</MicrosoftExtensionsLoggingConsolePackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ValidateCommandTests : TestBase
[Fact]
public async Task ValidateCommand_BasicTest_InvalidTemplate()
{
CliRootCommand root = new()
RootCommand root = new()
{
new ValidateCommand()
};
Expand All @@ -26,7 +26,7 @@ public async Task ValidateCommand_BasicTest_InvalidTemplate()
[Fact]
public async Task ValidateCommand_BasicTest_ValidTemplate()
{
CliRootCommand root = new()
RootCommand root = new()
{
new ValidateCommand()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Microsoft.TemplateEngine.Authoring.CLI.Commands
{
/// <summary>
/// Represents a <see cref="CliCommand"/> together with its action.
/// Represents a <see cref="Command"/> together with its action.
/// </summary>
internal abstract class ExecutableCommand<TModel> : CliCommand where TModel : class
internal abstract class ExecutableCommand<TModel> : Command where TModel : class
{
internal ExecutableCommand(string name, string? description = null)
: base(name, description)
Expand All @@ -29,7 +29,7 @@ internal ExecutableCommand(string name, string? description = null)
/// </summary>
protected abstract Task<int> ExecuteAsync(TModel args, ILoggerFactory loggerFactory, CancellationToken cancellationToken);

private sealed class CommandAction : AsynchronousCliAction
private sealed class CommandAction : AsynchronousCommandLineAction
{
private readonly ExecutableCommand<TModel> _command;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,72 @@ internal class VerifyCommand : ExecutableCommand<VerifyCommandArgs>
{
private const string CommandName = "verify";

private readonly CliArgument<string> _templateNameArgument = new("template-short-name")
private readonly Argument<string> _templateNameArgument = new("template-short-name")
{
Description = LocalizableStrings.command_verify_help_templateName_description,
// 0 for case where only path is specified
Arity = new ArgumentArity(1, 1)
};

private readonly CliOption<string> _remainingArguments = new("--template-args")
private readonly Option<string> _remainingArguments = new("--template-args")
{
Description = "Template specific arguments - all joined into single enquoted string. Any needed quotations of actual arguments has to be escaped.",
Arity = new ArgumentArity(0, 1)
};

private readonly CliOption<string> _templatePathOption = new("--template-path", "-p")
private readonly Option<string> _templatePathOption = new("--template-path", "-p")
{
Description = LocalizableStrings.command_verify_help_templatePath_description,
};

private readonly CliOption<string> _templateOutputPathOption = new("--output", "-o")
private readonly Option<string> _templateOutputPathOption = new("--output", "-o")
{
Description = LocalizableStrings.command_verify_help_outputPath_description,
};

private readonly CliOption<string> _snapshotsDirectoryOption = new("--snapshots-directory", "-d")
private readonly Option<string> _snapshotsDirectoryOption = new("--snapshots-directory", "-d")
{
Description = LocalizableStrings.command_verify_help_snapshotsDirPath_description,
};

private readonly CliOption<string> _scenarioNameOption = new("--scenario-name")
private readonly Option<string> _scenarioNameOption = new("--scenario-name")
{
Description = LocalizableStrings.command_verify_help_scenarioName_description,
};

private readonly CliOption<bool> _disableDiffToolOption = new("--disable-diff-tool")
private readonly Option<bool> _disableDiffToolOption = new("--disable-diff-tool")
{
Description = LocalizableStrings.command_verify_help_disableDiffTool_description,
};

private readonly CliOption<bool> _disableDefaultExcludePatternsOption = new("--disable-default-exclude-patterns")
private readonly Option<bool> _disableDefaultExcludePatternsOption = new("--disable-default-exclude-patterns")
{
Description = LocalizableStrings.command_verify_help_disableDefaultExcludes_description,
};

private readonly CliOption<IEnumerable<string>> _excludePatternOption = new("--exclude-pattern")
private readonly Option<IEnumerable<string>> _excludePatternOption = new("--exclude-pattern")
{
Description = LocalizableStrings.command_verify_help_customExcludes_description,
Arity = new ArgumentArity(0, 999)
};

private readonly CliOption<IEnumerable<string>> _includePatternOption = new("--include-pattern")
private readonly Option<IEnumerable<string>> _includePatternOption = new("--include-pattern")
{
Description = LocalizableStrings.command_verify_help_customIncludes_description,
Arity = new ArgumentArity(0, 999)
};

private readonly CliOption<bool> _verifyCommandOutputOption = new("--verify-std")
private readonly Option<bool> _verifyCommandOutputOption = new("--verify-std")
{
Description = LocalizableStrings.command_verify_help_verifyOutputs_description,
};

private readonly CliOption<bool> _isCommandExpectedToFailOption = new("--fail-expected")
private readonly Option<bool> _isCommandExpectedToFailOption = new("--fail-expected")
{
Description = LocalizableStrings.command_verify_help_expectFailure_description,
};

private readonly CliOption<IEnumerable<UniqueForOption>> _uniqueForOption = new("--unique-for")
private readonly Option<IEnumerable<UniqueForOption>> _uniqueForOption = new("--unique-for")
{
Description = LocalizableStrings.command_verify_help_uniqueFor_description,
Arity = new ArgumentArity(0, 999),
Expand Down Expand Up @@ -171,9 +171,9 @@ await engine.Execute(
}

/// <summary>
/// Case insensitive version for <see cref="CliOption{T}.AcceptOnlyFromAmong(string[])"/>.
/// Case insensitive version for <see cref="Option{T}.AcceptOnlyFromAmong(string[])"/>.
/// </summary>
private static void FromAmongCaseInsensitive(CliOption<IEnumerable<UniqueForOption>> option, string[]? allowedValues = null, string? allowedHiddenValue = null)
private static void FromAmongCaseInsensitive(Option<IEnumerable<UniqueForOption>> option, string[]? allowedValues = null, string? allowedHiddenValue = null)
{
allowedValues ??= [];
option.Validators.Add(optionResult => ValidateAllowedValues(optionResult, allowedValues, allowedHiddenValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.TemplateEngine.Authoring.CLI.Commands
{
internal class LocalizeCommand : CliCommand
internal class LocalizeCommand : Command
{
internal LocalizeCommand()
: base("localize")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ internal sealed class ExportCommand : ExecutableCommand<ExportCommandArgs>
{
private const string CommandName = "export";

private readonly CliArgument<IEnumerable<string>> _templatePathArgument = new("template-path")
private readonly Argument<IEnumerable<string>> _templatePathArgument = new("template-path")
{
Arity = ArgumentArity.OneOrMore,
Description = LocalizableStrings.command_export_help_templatePath_description,
};

private readonly CliOption<IEnumerable<string>> _languageOption = new("--language", "-l")
private readonly Option<IEnumerable<string>> _languageOption = new("--language", "-l")
{
Description = LocalizableStrings.command_export_help_language_description,
Arity = ArgumentArity.OneOrMore,
AllowMultipleArgumentsPerToken = true,
};

private readonly CliOption<bool> _recursiveOption = new("recursive", new[] { "--recursive", "-r" })
private readonly Option<bool> _recursiveOption = new("recursive", new[] { "--recursive", "-r" })
{
Description = LocalizableStrings.command_export_help_recursive_description,
};

private readonly CliOption<bool> _dryRunOption = new("--dry-run", "-d")
private readonly Option<bool> _dryRunOption = new("--dry-run", "-d")
{
Description = LocalizableStrings.command_export_help_dryrun_description,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class ValidateCommand : ExecutableCommand<ValidateCommandArgs>
{
private const string CommandName = "validate";

private readonly CliArgument<string> _templateLocationArg = new("template-location")
private readonly Argument<string> _templateLocationArg = new("template-location")
{
Description = LocalizableStrings.command_validate_help_description,
Arity = new ArgumentArity(1, 1)
Expand Down
6 changes: 3 additions & 3 deletions tools/Microsoft.TemplateEngine.Authoring.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ internal sealed class Program
{
internal static Task<int> Main(string[] args)
{
CliRootCommand rootCommand = new("dotnet-template-authoring");
RootCommand rootCommand = new("dotnet-template-authoring");
rootCommand.Subcommands.Add(new LocalizeCommand());
rootCommand.Subcommands.Add(new VerifyCommand());
rootCommand.Subcommands.Add(new ValidateCommand());

return GetCommandLineConfiguration(rootCommand).InvokeAsync(args);
}

internal static CliConfiguration GetCommandLineConfiguration(CliCommand command)
internal static CommandLineConfiguration GetCommandLineConfiguration(Command command)
{
return new CliConfiguration(command)
return new CommandLineConfiguration(command)
{
EnablePosixBundling = false
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class Program
{
private static async Task<int> Main(string[] args)
{
CliCommand rootCommand = new TemplateDiscoveryCommand();
Command rootCommand = new TemplateDiscoveryCommand();
return await rootCommand.Parse(args).InvokeAsync().ConfigureAwait(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,77 +9,77 @@

namespace Microsoft.TemplateSearch.TemplateDiscovery
{
internal class TemplateDiscoveryCommand : CliCommand
internal class TemplateDiscoveryCommand : Command
{
private const int DefaultPageSize = 100;

private readonly CliOption<DirectoryInfo> _basePathOption = new("--basePath")
private readonly Option<DirectoryInfo> _basePathOption = new("--basePath")
{
Arity = ArgumentArity.ExactlyOne,
Description = "The root dir for output for this run.",
Required = true
};

private readonly CliOption<bool> _allowPreviewPacksOption = new("--allowPreviewPacks")
private readonly Option<bool> _allowPreviewPacksOption = new("--allowPreviewPacks")
{
Description = "Include preview packs in the results (by default, preview packs are ignored and the latest stable pack is used.",
};

private readonly CliOption<int> _pageSizeOption = new("--pageSize")
private readonly Option<int> _pageSizeOption = new("--pageSize")
{
Description = "(debugging) The chunk size for interactions with the source.",
DefaultValueFactory = (r) => DefaultPageSize,
};

private readonly CliOption<bool> _onePageOption = new("--onePage")
private readonly Option<bool> _onePageOption = new("--onePage")
{
Description = "(debugging) Only process one page of template packs.",
};

private readonly CliOption<bool> _savePacksOption = new("--savePacks")
private readonly Option<bool> _savePacksOption = new("--savePacks")
{
Description = "Don't delete downloaded candidate packs (by default, they're deleted at the end of a run).",
};

private readonly CliOption<bool> _noTemplateJsonFilterOption = new("--noTemplateJsonFilter")
private readonly Option<bool> _noTemplateJsonFilterOption = new("--noTemplateJsonFilter")
{
Description = "Don't prefilter packs that don't contain any template.json files (this filter is applied by default).",
};

private readonly CliOption<bool> _verboseOption = new("--verbose", "-v")
private readonly Option<bool> _verboseOption = new("--verbose", "-v")
{
Description = "Verbose output for template processing.",
};

private readonly CliOption<bool> _testOption = new("--test", "-t")
private readonly Option<bool> _testOption = new("--test", "-t")
{
Description = "Run tests on generated metadata files.",
};

private readonly CliOption<SupportedQueries[]> _queriesOption = new("--queries")
private readonly Option<SupportedQueries[]> _queriesOption = new("--queries")
{
Arity = ArgumentArity.OneOrMore,
Description = $"The list of providers to run. Supported providers: {string.Join(",", Enum.GetValues<SupportedQueries>())}.",
AllowMultipleArgumentsPerToken = true,
};

private readonly CliOption<DirectoryInfo> _packagesPathOption = new CliOption<DirectoryInfo>("--packagesPath")
private readonly Option<DirectoryInfo> _packagesPathOption = new Option<DirectoryInfo>("--packagesPath")
{
Description = "Path to pre-downloaded packages. If specified, the packages won't be downloaded from NuGet.org."
}.AcceptExistingOnly();

private readonly CliOption<bool> _diffOption = new("--diff")
private readonly Option<bool> _diffOption = new("--diff")
{
Description = "The list of packages will be compared with previous run, and if package version is not changed, the package won't be rescanned.",
DefaultValueFactory = (r) => true,
};

private readonly CliOption<FileInfo> _diffOverrideCacheOption = new CliOption<FileInfo>("--diff-override-cache")
private readonly Option<FileInfo> _diffOverrideCacheOption = new Option<FileInfo>("--diff-override-cache")
{
Description = "Location of current search cache (local path only).",
}.AcceptExistingOnly();

private readonly CliOption<FileInfo> _diffOverrideNonPackagesOption = new CliOption<FileInfo>("--diff-override-non-packages")
private readonly Option<FileInfo> _diffOverrideNonPackagesOption = new Option<FileInfo>("--diff-override-non-packages")
{
Description = "Location of the list of packages known not to be a valid package (local path only).",
}.AcceptExistingOnly();
Expand Down