Releases: dotmake-build/command-line
DotMake.CommandLine v1.8.8
- Updated to latest daily build 2.0.0-beta4.24324.3 of System.CommandLine.
- Fixed: CliSettings.ResponseFileTokenReplacer should use the default StringExtensions.TryReadResponseFile from System.CommandLine
so that response files should work out of the box. - Updated docs regarding bundled options, directives and response files features.
DotMake.CommandLine v1.8.7
- Updated to latest daily build 2.0.0-beta4.24201.1 of System.CommandLine.
- Added support for command handlers or command as delegates without the async keyword (which returns Task or Task<int>).
DotMake.CommandLine v1.8.6
- Added parent command accessor support. Sub-commands can get a reference to the parent command by adding a property of the parent command type.
- ParseResultExtensions.Bind improvement: Binding will be done only once per definition class, so calling this method consecutively for
the same definition class will return the cached result.
// Sub-commands can get a reference to the parent command by adding a property of the parent command type.
[CliCommand(Description = "A root cli command with children that can access parent commands")]
public class ParentCommandAccessorCliCommand
{
[CliOption(
Description = "This is a global option (Recursive option on the root command), it can appear anywhere on the command line",
Recursive = true)]
public string GlobalOption1 { get; set; } = "DefaultForGlobalOption1";
[CliArgument(Description = "Description for RootArgument1")]
public string RootArgument1 { get; set; }
public void Run(CliContext context)
{
context.ShowValues();
}
[CliCommand(Description = "A nested level 1 sub-command which accesses the root command")]
public class Level1SubCliCommand
{
[CliOption(
Description = "This is global for all sub commands (it can appear anywhere after the level-1 verb)",
Recursive = true)]
public string Level1RecursiveOption1 { get; set; } = "DefaultForLevel1RecusiveOption1";
[CliArgument(Description = "Description for Argument1")]
public string Argument1 { get; set; }
// The parent command gets automatically injected
public ParentCommandAccessorCliCommand RootCommand { get; set; }
public void Run(CliContext context)
{
context.ShowValues();
}
[CliCommand(Description = "A nested level 2 sub-command which accesses its parent commands")]
public class Level2SubCliCommand
{
[CliOption(Description = "Description for Option1")]
public string Option1 { get; set; } = "DefaultForOption1";
[CliArgument(Description = "Description for Argument1")]
public string Argument1 { get; set; }
// All ancestor commands gets injected
public ParentCommandAccessorCliCommand RootCommand { get; set; }
public Level1SubCliCommand ParentCommand { get; set; }
public void Run(CliContext context)
{
context.ShowValues();
Console.WriteLine();
Console.WriteLine(@$"Level1RecursiveOption1 = {ParentCommand.Level1RecursiveOption1}");
Console.WriteLine(@$"parent Argument1 = {ParentCommand.Argument1}");
Console.WriteLine(@$"GlobalOption1 = {RootCommand.GlobalOption1}");
Console.WriteLine(@$"RootArgument1 = {RootCommand.RootArgument1}");
}
}
}
}
DotMake.CommandLine v1.8.5
DotMake.CommandLine v1.8.4
-
Updated to latest daily build
2.0.0-beta4.24126.1
of System.CommandLine. -
Fixed compiler error related to CliServiceProviderExtensions and CliServiceCollectionExtensions when project is referenced
by another project. Class conflict errors occur due to same namespace in different assemblies.This can't be fixed via PrivateAssets in PackageReference because although default value is "contentfiles;analyzers;build",
source generator still flows to the parent project via ProjectReference and PrivateAssets="all" prevents flow of
source generator but it also prevents flow of "compile" so it becomes useless.First attempt to fix (in v1.8.3), was making CliServiceProviderExtensions and CliServiceCollectionExtensions
classes internal but the problem resurfaces if user adds InternalsVisibleTo attribute in child project.So we finally solve this problem, by detecting if current compilation is a parent project in the solution,
if so we do not inject feature extensions as they already come transitively from the child project.
This way we can also keep CliServiceProviderExtensions and CliServiceCollectionExtensions classes public.
DotMake.CommandLine v1.8.3
- Fixed "CS0436 : The type 'CliServiceProviderExtensions' in ..." compiler error when project is referenced by another project.
- Generated Builder classes will be put in
GeneratedCode
sub-namespace of the definition class's namespace to prevent namespace pollution.
GlobalGeneratedCode
namespace was already being used by delegate-model, now class-based model will useGeneratedCode
sub-namespace.
DotMake.CommandLine v1.8.2
- Updated to latest daily build
2.0.0-beta4.24123.1
of System.CommandLine. - Better error messages when a passed class does not have a
[CliCommand]
attribute or it's a nested class and one of its parents
does not have a[CliCommand]
attribute. - On Windows platform, backslash + double quote (
\"
) at the end of an argument,
is usually a path separator and not an escape for double quote, so it will be trimmed to prevent unnecessary path errors.
Related to dotnet/command-line-api#2334, dotnet/command-line-api#2276, dotnet/command-line-api#354
DotMake.CommandLine v1.8.1
-
Added support for other dependency injection containers (e.g. Autofac) when
onlyMicrosoft.Extensions.DependencyInjection.Abstractions
package (version >= 2.1.1) is added to the project.
You can set your custom service provider with the extension methodCli.Ext.SetServiceProvider
.
In previous version, this method already existed but accepted aServiceProvider
parameter, instead of
IServiceProvider
parameter which allows 3rd party implementations other than the default one inMicrosoft.Extensions.DependencyInjection
.using DotMake.CommandLine; using Autofac.Core; using Autofac.Core.Registration; var cb = new ContainerBuilder(); cb.RegisterType<object>(); var container = cb.Build(); Cli.Ext.SetServiceProvider(container); Cli.Run<RootCliCommand>();
-
Reduced minimum version requirement for
Microsoft.Extensions.DependencyInjection
from6.0.0
to2.1.1
so that you don't need to update it in legacy projects. AddedCli.Ext.GetServiceCollection
and
Cli.Ext.GetServiceProviderOrDefault
extension methods.
DotMake.CommandLine v1.8.0
-
Switched to using latest daily builds of System.CommandLine (currently
2.0.0-beta4.24112.1
).
Since official2.0.0-beta4.22272.1
release (dated 6/2/2022), System.CommandLine API is vastly changed
so we migrated those changes to DotMake.CommandLine, this way we can get all the bug fixes.As daily builds are only published to Microsoft's private feed and not to official NuGet site,
we dropped the dependency to System.CommandLine package and instead we are now bundling System.CommandLine DLLs inside our
own NuGet package. Once System.CommandLine becomes GA and latest version is published to official NuGet site,
we will readd the dependency to System.CommandLine package. -
Renamed Global property in CliOptionAttribute to Recursive to match new System.CommandLine API.
-
In
Cli.Run
andCli.RunAsync
methods; configureBuilder, useBuilderDefaults, console parameters are removed and
instead they now accept newCliSettings
parameter, which is used to configure settings in one place. -
In
Cli.Parse
methods return type is now ParseResult and ParseResult.Bind method can be used to get an instance for
the command definition class. -
InvocationContext
in System.CommandLine latest builds, is removed so we added a new class namedCliContext
which supports command invocation by providing access to parse results and other services.
DotMake.CommandLine v1.7.2
-
Added advanced validation. In
[CliOption]
and[CliArgument]
attributes, removedAllowExisting
property and addedValidationRules
,ValidationPattern
,ValidationMessage
properties.
ValidationRules
property allows setting predefined validation rules such asExistingFile
,NonExistingFile
,ExistingDirectory
,
NonExistingDirectory
,ExistingFileOrDirectory
,NonExistingFileOrDirectory
,LegalPath
,LegalFileName
,LegalUri
,LegalUrl
.
Validation rules can be combined.
ValidationPattern
property allows setting a regular expression pattern for custom validation,
andValidationMessage
property allows setting a custom error message to show whenValidationPattern
does not match.[CliCommand] public class ValidationCliCommand { [CliOption(Required = false, ValidationRules = CliValidationRules.ExistingFile)] public FileInfo OptFile1 { get; set; } [CliOption(Required = false, ValidationRules = CliValidationRules.NonExistingFile | CliValidationRules.LegalPath)] public string OptFile2 { get; set; } [CliOption(Required = false, ValidationRules = CliValidationRules.ExistingDirectory)] public DirectoryInfo OptDir { get; set; } [CliOption(Required = false, ValidationPattern = @"(?i)^[a-z]+$")] public string OptPattern1 { get; set; } [CliOption(Required = false, ValidationPattern = @"(?i)^[a-z]+$", ValidationMessage = "Custom error message")] public string OptPattern2 { get; set; } [CliOption(Required = false, ValidationRules = CliValidationRules.LegalUrl)] public string OptUrl { get; set; } [CliOption(Required = false, ValidationRules = CliValidationRules.LegalUri)] public string OptUri { get; set; } [CliArgument(Required = false, ValidationRules = CliValidationRules.LegalFileName)] public string OptFileName { get; set; } public void Run(InvocationContext context) { context.ShowValues(); } }