public HandleAnswer(CommandContext context, StringAnswerHandler handler) { _type = AnswerType.String; _options = context.HttpContext.RequestServices.GetRequiredService <IOptions <BeavisCliOptions> >().Value; _stringAnswerHandler = handler; _context = context; }
private static Task <CommandResult> AskQuestion(CommandContext context, string[] questions, bool useMask, StringAnswerHandler stringHandler, BooleanAnswerHandler booleanHandler) { // this will be invoked just before we are sending the response context.Response.Sending += (sender, args) => { IJobPool pool = context.HttpContext.RequestServices.GetRequiredService <IJobPool>(); IJob job; if (stringHandler != null) { job = new HandleAnswer(context, stringHandler); } else if (booleanHandler != null) { job = new HandleAnswer(context, booleanHandler); } else { throw new InvalidOperationException($"{nameof(StringAnswerHandler)} or {nameof(BooleanAnswerHandler)} must be set."); } string key = pool.Push(job); foreach (string question in questions) { context.WriteText(question); } // disable terminal prompt context.WriteJs(new SetPrompt("")); // disable terminal history -> this will set back to 'enabled' in HandleAnswerJob context.WriteJs(new SetHistory(false)); if (useMask) { context.WriteJs(new SetMask(true)); context.WriteJs(new QueueJob(key, new SetMask(false))); } else { context.WriteJs(new QueueJob(key)); } }; return(Task.FromResult(CommandResult.Default)); }
public static Task <CommandResult> AskPassword(this CommandContext context, string question, StringAnswerHandler handler) { return(AskQuestion(context, new[] { question }, true, handler, null)); }