コード例 #1
0
        public override ValueTask <int> DispatchAsync(CommandDispatchContext ctx)
        {
            var hasHelpOption = ctx.ParsedCommandLine.Options.Any(x => x.Option == BuiltInCommandOption.Help);

            if (hasHelpOption)
            {
                var feature           = _appContext.Current !.Features.Get <ICoconaCommandFeature>() !;
                var commandCollection = feature.CommandCollection ?? _commandProvider.GetCommandCollection();

                var help = (ctx.Command.IsPrimaryCommand)
                    ? _commandHelpProvider.CreateCommandsIndexHelp(commandCollection, feature.CommandStack)
                    : _commandHelpProvider.CreateCommandHelp(ctx.Command, feature.CommandStack);

                _console.Output.Write(_helpRenderer.Render(help));
                return(new ValueTask <int>(129));
            }

            var hasVersionOption = ctx.ParsedCommandLine.Options.Any(x => x.Option == BuiltInCommandOption.Version);

            if (hasVersionOption)
            {
                _console.Output.Write(_helpRenderer.Render(_commandHelpProvider.CreateVersionHelp()));
                return(new ValueTask <int>(0));
            }

            return(Next(ctx));
        }
コード例 #2
0
 public ValueTask <int> ShowVersion(
     [FromService] ICoconaCommandHelpProvider commandHelpProvider,
     [FromService] ICoconaConsoleProvider console,
     [FromService] ICoconaHelpRenderer helpRenderer
     )
 {
     console.Output.Write(helpRenderer.Render(commandHelpProvider.CreateVersionHelp()));
     return(new ValueTask <int>(0));
 }
コード例 #3
0
        public override ValueTask <int> DispatchAsync(CommandDispatchContext ctx)
        {
            var hasHelpOption = ctx.ParsedCommandLine.Options.Any(x => x.Option == BuiltInCommandOption.Help);

            if (hasHelpOption)
            {
                var help = (ctx.Command.IsPrimaryCommand)
                    ? _commandHelpProvider.CreateCommandsIndexHelp(_commandProvider.GetCommandCollection())
                    : _commandHelpProvider.CreateCommandHelp(ctx.Command);

                _console.Output.Write(_helpRenderer.Render(help));
                return(new ValueTask <int>(129));
            }

            var hasVersionOption = ctx.ParsedCommandLine.Options.Any(x => x.Option == BuiltInCommandOption.Version);

            if (hasVersionOption)
            {
                _console.Output.Write(_helpRenderer.Render(_commandHelpProvider.CreateVersionHelp()));
                return(new ValueTask <int>(0));
            }

            return(Next(ctx));
        }