示例#1
0
        public Task <int> Execute(IConfiguration configuration, IEnumerable <string> args)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            // Create the command model.
            var model = CommandModelBuilder.Build(configuration);

            // Parse and map the model against the arguments.
            var parser       = new CommandTreeParser(model);
            var parsedResult = parser.Parse(args);

            // Currently the root?
            if (parsedResult.Tree == null)
            {
                // Display help.
                ConsoleRenderer.Render(HelpWriter.Write(model));
                return(Task.FromResult(0));
            }

            // Get the command to execute.
            var leaf = parsedResult.Tree.GetLeafCommand();

            if (leaf.Command.IsBranch || leaf.ShowHelp)
            {
                // Branches can't be executed. Show help.
                ConsoleRenderer.Render(HelpWriter.WriteCommand(model, leaf.Command));
                return(Task.FromResult(leaf.ShowHelp ? 0 : 1));
            }

            // Register the arguments with the container.
            _registrar?.RegisterInstance(typeof(IRemainingArguments), parsedResult.Remaining);

            // Create the resolver and the context.
            var resolver = new TypeResolverAdapter(_registrar?.Build());
            var context  = new CommandContext(parsedResult.Remaining);

            // Execute the command tree.
            return(Execute(leaf, parsedResult.Tree, context, resolver));
        }
示例#2
0
        public static void Render(IRenderable renderable, IConsoleWriter?console)
        {
            var renderer = new ConsoleRenderer(console);

            renderable.Render(renderer);
        }
示例#3
0
        public static void Render(IRenderable?renderable, IConsoleSettings?console)
        {
            var renderer = new ConsoleRenderer(console);

            renderer.Render(renderable);
        }
示例#4
0
 public Scope(ConsoleRenderer renderer, ConsoleColorType type)
 {
     _renderer = renderer;
     _type     = type;
 }