public static CommandLineBuilder UseVersionOption( this CommandLineBuilder builder) { if (builder.Command.Children.GetByAlias("--version") != null) { return(builder); } var versionOption = new Option("--version", "Show version information"); builder.AddOption(versionOption); builder.AddMiddleware(async(context, next) => { if (context.ParseResult.HasOption(versionOption)) { context.Console.Out.WriteLine(_assemblyVersion.Value); } else { await next(context); } }, MiddlewareOrderInternal.VersionOption); return(builder); }
public static CommandLineBuilder AddVersionOption( this CommandLineBuilder builder) { var versionOption = new Option("--version", "Display version information"); builder.AddOption(versionOption); builder.AddMiddleware(async(context, next) => { if (context.ParseResult.HasOption(versionOption)) { context.Console.Out.WriteLine(_assemblyVersion.Value); } else { await next(context); } }, CommandLineBuilder.MiddlewareOrder.Preprocessing); return(builder); }
public static CommandLineBuilder ConfigureFromType <T>( this CommandLineBuilder builder, MethodInfo onExecuteMethod = null) where T : class { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var typeBinder = new TypeBinder(typeof(T)); foreach (var option in typeBinder.BuildOptions()) { builder.AddOption(option); } builder.Handler = new TypeBindingCommandHandler( onExecuteMethod, typeBinder); return(builder); }