Skip to content

Move CommandLineBuilder into the application framework layer #1920

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

Closed
Tracked by #1891
jonsequitur opened this issue Nov 2, 2022 · 0 comments · Fixed by #2107
Closed
Tracked by #1891

Move CommandLineBuilder into the application framework layer #1920

jonsequitur opened this issue Nov 2, 2022 · 0 comments · Fixed by #2107
Assignees
Labels
Milestone

Comments

@jonsequitur
Copy link
Contributor

jonsequitur commented Nov 2, 2022

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants