Skip to content

Releases: dotmake-build/command-line

DotMake.CommandLine v3.5.0

08 May 14:49

Choose a tag to compare

  • Added: Created CliWriter class which provides styled terminal output (color and text decoration),
    using ANSI escape sequences when supported and console-native fallbacks otherwise.
    CliContext.Output, CliContext.Error, HelpContext.Output properties will now return a CliWriter
    instance so that user too can write styled output.
    Also added Cli.Output and Cli.Error properties for global access.

    CliWriter class currently provides these methods for styled output (on top of regular TextWriter methods):

    Write(CliStyle style, string value)
    Write(CliStyle style, string format, params object[] arg)
    
    WriteLine(CliStyle style, string value)
    WriteLine(CliStyle style, string format, params object[] arg)
    
    WriteLink(CliLink link, CliStyle style, string value)
    WriteLink(CliLink link, CliStyle style, string format, params object[] arg)
    WriteLink(CliLink link, string value)
    WriteLink(CliLink link, string format, params object[] arg)
    
    SetStyle(CliStyle style)
    ResetStyle()

    More methods for writing common Success, Warning, Error messages with default styles are planned to be added in future versions.

    For custom use, you can also get get a cached CliWriter so that ANSI support detection is only done once per Console.Out:

    var cliWriter = CliWriter.GetCached(Console.Out);
  • Improved: CliTheme now uses new class CliStyle for its properties, which itself includes Foreground, Background
    and Decoration properties.
    Default themes from now on will not set Foreground or Background for DefaultStyle (main color),
    for example CliTheme.Default will only use CliDecoration.Bold for FirstColumnStyle property instead of white color.
    This is because detecting current terminal colors is impossible and for example on OSX terminal with dark mode,
    text became invisible as we made assumptions (to fix color visibility) that on OSX terminal background color is usually white.

  • Fixed: An item with the same key has already been added. error when Cli.RunAsync() is called
    in tests that re running in parallel (expecially with TUnit).
    Ensured ArgumentConverter.RegisterStringConverter() and ArgumentConverter.RegisterCollectionConverter()
    use ConcurrentDictionary and GetOrAdd for preventing multi-thread racing problems.

DotMake.CommandLine v3.2.0

14 Apr 01:56

Choose a tag to compare

  • Improved: Updated to version 2.0.5 of System.CommandLine.

  • Added: Mutually exclusive option groups.
    To declare that options are mutually exclusive, assign them the same Group in [CliOption] attributes:

    [CliCommand(Description = "Display different file formats")]
    public class FormatCommand
    {
        [CliOption(Group = "Format", Description = "Output as XML")]
        public bool Xml { get; set; }
    
        [CliOption(Group = "Format", Description = "Output as JSON")]
        public bool Json { get; set; }  
    
        [CliOption(Description = "Verbosity level", Required = false)]
        public string Verbose { get; set; }
    
        public void Run(CliContext context)
        {
            context.ShowValues();
        }
     }

    Sometimes you want to enforce that exactly one option from a group must be specified.
    This is done by setting the RequiredGroups property in [CliCommand] attribute and listing the group names:

    [CliCommand(RequiredGroups = new[] { "auth" })]
    public class ReportCommand
    {
        // Group 1: Output format (mutually exclusive)
        [CliOption(Group = "output-format")]
        public bool Json { get; set; }
    
        [CliOption(Group = "output-format")]
        public bool Xml { get; set; }
    
        // Group 2: Authentication (required group)
        [CliOption(Group = "auth")]
        public string ApiKey { get; set; }
    
        [CliOption(Group = "auth")]
        public string Token { get; set; }
        
        public void Run(CliContext context)
        {
            context.ShowValues();
        }
    }
  • Fixed: Localization did not work for inherited classes that existed in different files
    due to Syntax node is not within syntax tree error.

  • Improved: Show full informational version like 2.0.0+b0f34d51fccc69fd334253924abd8d6853fad7aa and not
    2.0.0 when version is explicitly asked with -v or --version option.

  • Fixed: Attempt to fix CliNamer.AddTokenOrThrow name conflicting errors when Cli.Parse() is called
    in tests that are running in parallel. Also ensure subcommand names and aliases are properly checked for conflicts.

DotMake.CommandLine v3.1.0

09 Dec 22:22

Choose a tag to compare

  • Improved: Added new class CliRunnableResult which derives from CliResult and adds Run and RunAsync methods
    running the handler for the called command.
    Changed return type of Cli.Parse and CliParser.Parse methods from CliResult to CliRunnableResult
    So now you can do:

    var result = Cli.Parse<RootCliCommand>();
    return result.Run();
    
    //or
    var parser = Cli.GetParser<RootCliCommand>();
    var result = parser.Parse(args);
    return result.Run();     
  • Changed: Deprecated CliContext.IsEmptyCommand() and CliContext.IsEmpty(), use new properties
    !CliContext.Result.HasArgs and !CliContext.Result.HasTokens instead.
    These are better suited to be in CliResult and naming should better clarify the purpose.

  • Fixed: QualifiedSyntaxRewriter to support fully qualify generic name syntax like Array.Empty<CustomClass>().
    Changed handling so that IdentifierNameSyntax anywhere is converted to fully qualified.

  • Fixed: Calling Cli.Ext.ConfigureServices will reset existing service provider if it was already built or set,
    so that changed service collection can take effect:

    var result = Cli.Parse<IStartupOptions>(args);
    var startupOptions = result.Bind<IStartupOptions>();
    
    //This works now, the existing service builder (caused by Cli.Parse) will be reset
    Cli.Ext.ConfigureServices(services =>
    {
        services.AddSingleton(startupOptions);
        services.AddSingleton<Dependency>();
    });
    
    await Cli.RunAsync<RootCommand>(args);          

DotMake.CommandLine v3.0.0

11 Nov 23:29

Choose a tag to compare

  • Improved: Updated to final version 2.0.0 of System.CommandLine.

  • Improved: Remove SourceRevisionId (commit id) from AssemblyInformationalVersion (<InformationalVersion>)
    so that displayed app version and result of --version command is clean and concise.
    For example display MyApp v2.0.0 instead of MyApp v2.0.0+b0f34d51fccc69fd334253924abd8d6853fad7aa.

DotMake.CommandLine v2.8.2

12 Oct 13:25

Choose a tag to compare

  • Fixed: All types in generated code will now be prefixed with global namespace global:: to prevent
    CS0234 errors (namespace and type conflict compile errors) which can happen when user names a namespace part and a class same.
    Example code to replicate the problem (now fixed), note the .TestApp, .System, .DotMake
    as the final part of the namespace which triggered the problem:

    using DotMake.CommandLine;
    
    //Generated code should not fail to compile even if user uses some crazy namespaces
    
    namespace TestApp.Commands.TestApp
    {
        [CliCommand]
        public class TestAppCliCommand
        {
            [CliArgument(Arity = CliArgumentArity.ZeroOrMore)]
            public string Arg { get; set; }
        }
    }
    
    namespace TestApp.Commands.System
    {
        [CliCommand]
        public class SystemCliCommand
        {
    
        }
    }
    
    namespace TestApp.Commands.DotMake
    {
        [CliCommand]
        public class DotMakeCliCommand
        {
    
        }
    }
  • Improved: Documentation for CliContext.IsEmptyCommand() and CliContext.IsEmpty() to emphasize the difference.

DotMake.CommandLine v2.8.1

27 Sep 08:12

Choose a tag to compare

  • Fixed: Help was no longer printed for subcommands with a required argument with v2.8.0.
    This happened due to the update to 2.0.0-rc.1.25451.107 of System.CommandLine.
    There is a new property ClearsParseErrors in SynchronousCommandLineAction
    which from now on, should be overridden to return true for our custom actions like CustomHelpAction and VersionOptionAction.
    Normally our CliHelpBuilder checks for ParseResult.Errors.Count > 0 to avoid printing help when there is a parsing error.
    So as ClearsParseErrors was not set to true, CliHelpBuilder was not printing help as it thought there was a parse error
    i.e. Required argument missing for command, even though -? or -h was passed.

DotMake.CommandLine v2.8.0

12 Sep 19:22

Choose a tag to compare

  • Improved: Updated to version 2.0.0-rc.1.25451.107 of System.CommandLine.
  • Added: MaxWidthproperty to CustomHelpAction
    and ensure correct maxWidth parameter in CliHelpBuilder constructor if not specified.

DotMake.CommandLine v2.7.1

02 Sep 19:56

Choose a tag to compare

  • Fixed: Foreground color is always white on macOS regardless of theme settings.

DotMake.CommandLine v2.7.0

16 Aug 14:42

Choose a tag to compare

  • Updated to version 2.0.0-beta7.25380.108 of System.CommandLine.

DotMake.CommandLine v2.6.8

11 Aug 09:33

Choose a tag to compare

  • Added: Command and RootCommand properties to CliParser class:

    var parser = Cli.GetParser<RootCliCommand>();
    
    //Access the command that is used to parse the command line input.
    var command = parser.Command;
    
    //Access the root of the command that is used to parse the command line input.
    //If parser.Command is already a root command, this will be same instance.
    //If it's a sub-command, it will be the root of that sub-command.
    var rootCommand = parser.RootCommand;
  • Fixed: SourceGenerator sometimes triggers a concurrency exception. Use ConcurrentDictionary for GenerationCounts.

  • Fixed: Do not add auto name or alias for root commands as it can unnecessarily conflict with children.