Skip to content

Move CommandLineBuilder into the application framework layer #1920

Closed
@jonsequitur

Description

@jonsequitur
namespace System.CommandLine.Builder
{
    public class CommandLineBuilder 
    {
        public CommandLineBuilder(Command rootCommand = null);
        public Command Command { get; }
        public Parser Build()
    }
 
    // All of the things that extend CommandLineBuilder should be instance members on CommandLineBuilder.
    // If UseHelpBuilder is providing namespace-based componentization then it can make sense here, but the type name is bad for it because
    //   a) it says it's extending CommandLineBuilder, but doesn't (necessarily) and b) should have a named purpose, not just "SomethingExtensions".
    public static class CommandLineBuilderExtensions 
    {
         // Is there only one environment variable, or is it multiple?  I feel like I'd expect plurality here, but don't know why.
        public static CommandLineBuilder UseEnvironmentVariableDirective(this CommandLineBuilder builder);
 
        // What happens if this is called twice?  If it's "last writer wins", then "Set" is a better verb than "Use". If it's accumulated, then Add.  Applies to all of the Use- methods.
        public static CommandLineBuilder UseExceptionHandler(this CommandLineBuilder builder, Action<Exception,InvocationContext> onException = null, int? errorExitCode = null);
 
        // The middle overload feels like it must be doing something very different than the other two.  You either need more overloads, or to rename something, or to remove the middle one, or something.
        public static CommandLineBuilder UseHelp(this CommandLineBuilder builder, int? maxWidth = null);
        public static CommandLineBuilder UseHelp(this CommandLineBuilder builder, string[] helpAliases);
        public static CommandLineBuilder UseHelp(this CommandLineBuilder builder, Action<HelpContext> customize, int? maxWidth = null);
        
        // Generic extension methods with no constraints are prohibited, otherwise they apply to object, which is prohibited.
        public static TBuilder UseHelpBuilder<TBuilder>(this TBuilder builder, Func<BindingContext,HelpBuilder> getHelpBuilder);
 
        public static CommandLineBuilder UseLocalizationResources(this CommandLineBuilder builder, LocalizationResources validationMessages);
        public static CommandLineBuilder UseParseDirective(this CommandLineBuilder builder, int? errorExitCode = null);
        public static CommandLineBuilder UseParseErrorReporting(this CommandLineBuilder builder, int? errorExitCode = null);
        public static CommandLineBuilder UseSuggestDirective(this CommandLineBuilder builder);
        
        // Does 0 disable it?  Seems like `int TypoCorrectionLevel { get; set; }` to me; or, if 0 doesn't disable it, make it `int?`
        public static CommandLineBuilder UseTypoCorrections(this CommandLineBuilder builder, int maxLevenshteinDistance = 3);

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions