static async Task <int> FullInvocationChainAsync(InvocationContext context)
            {
                InvocationMiddleware invocationChain = BuildInvocationChain(context, true);

                await invocationChain(context, _ => Task.CompletedTask);

                return(GetExitCode(context));
            }
Ejemplo n.º 2
0
        protected void AddMiddleware(InvocationMiddleware middleware, int order)
        {
            var middlewareListField = CliBuilder.GetType().GetField(
                "_middlewareList", BindingFlags.Instance | BindingFlags.NonPublic);
            var fieldValue     = middlewareListField !.GetValue(CliBuilder);
            var middlewareList = (List <(InvocationMiddleware, int)>)fieldValue !;

            middlewareList.Add((middleware, order));
        }
        public int Invoke(IConsole?console = null)
        {
            var context = new InvocationContext(parseResult, console);

            InvocationMiddleware invocationChain = BuildInvocationChain(context);

            Task.Run(() => invocationChain(context, invocationContext => Task.CompletedTask)).GetAwaiter().GetResult();

            return(GetResultCode(context));
        }
        public async Task <int> InvokeAsync(IConsole?console = null)
        {
            var context = new InvocationContext(parseResult, console);

            InvocationMiddleware invocationChain = BuildInvocationChain(context);

            await invocationChain(context, invocationContext => Task.CompletedTask);

            return(GetResultCode(context));
        }
Ejemplo n.º 5
0
        public static CommandLineBuilder UseMiddleware(
            this CommandLineBuilder builder,
            InvocationMiddleware middleware)
        {
            builder.AddMiddleware(
                middleware,
                CommandLineBuilder.MiddlewareOrder.Middle);

            return(builder);
        }
Ejemplo n.º 6
0
        public int Invoke(IConsole?console = null)
        {
            var context = new InvocationContext(parseResult, console);

            InvocationMiddleware invocationChain = BuildInvocationChain(context);

            invocationChain(context, static _ => Task.CompletedTask).ConfigureAwait(false).GetAwaiter().GetResult();

            return(GetExitCode(context));
        }
        public static CommandLineBuilder UseMiddleware(
            this CommandLineBuilder builder,
            InvocationMiddleware middleware,
            MiddlewareOrder order = MiddlewareOrder.Default)
        {
            builder.AddMiddleware(
                middleware,
                order);

            return(builder);
        }
Ejemplo n.º 8
0
 public static CommandLineBuilder UseMiddlewareOrdered(this CommandLineBuilder builder, int order, InvocationMiddleware middleware)
 {
     addMiddlewareLazy.Value(builder, middleware, order);
     return(builder);
 }