public IEnumerable <IItem> GetHelp(Input input)
        {
            QueryNode query = tree.Root;

            foreach (Token token in input.Tokens)
            {
                if (token.Type != TokenTypeEnum.Query ||
                    !query.Queries.ContainsKey(token.Input))
                {
                    break;
                }

                query = query.Queries[token.Input];
            }

            foreach (Query subQuery in query.Query.Queries.OrderBy(q => q.Key))
            {
                yield return(Item.AsIntellisense(subQuery.GetMainRepresentation(), "query", subQuery.Documentation.Description));
            }

            foreach (Option subOption in query.Query.Options.OrderBy(o => o.Key))
            {
                string representation = subOption.GetMainRepresentation();
                yield return(Item.AsIntellisense($"--{representation}", "option", subOption.Documentation.Description));
            }

            if (!commandManagement.HasCommand(input.Context.Key))
            {
                yield break;
            }
        }
Пример #2
0
        private async Task ProcessInputAsync(Input inputModel, CancellationToken cancellation)
        {
            if (!inputModel.Context.IsValid)
            {
                if (fallback != null &&
                    string.IsNullOrEmpty(inputModel.Context.Key))
                {
                    Task <ICommandResult> fallbackTask = fallback.FallbackAsync(inputModel, cancellation);
                    await RenderAsync(inputModel, await fallbackTask, cancellation);
                }
                else if (didYouMean != null)
                {
                    Render(inputModel, didYouMean.Help(inputModel));
                }
                else
                {
                    RenderError(inputModel, "Unknown input.");
                }
                return;
            }

            if (!commandManagement.HasCommand(inputModel.Context.Key))
            {
                RenderError(inputModel, $"The command is not registered: {inputModel.Context.Key}.");
                return;
            }

            await ProcessContextAsync(inputModel, inputModel.Context, cancellation);
        }