private bool TryPreventExceptionWithPrompt(ArgHook.HookContext context)
{
if (parent.PromptIfMissing && ArgHook.HookContext.Current.Definition.IsNonInteractive == false)
{
var cli = new CliHelper();
ITabCompletionHandler tabHandler;
IHighlighterConfigurator highlighterConfigurator;
if (TabCompletionHandlerType.TryCreate<ITabCompletionHandler>(out tabHandler))
{
cli.Reader.TabHandler.TabCompletionHandlers.Add(tabHandler);
}
if (HighlighterConfiguratorType.TryCreate<IHighlighterConfigurator>(out highlighterConfigurator))
{
cli.Reader.Highlighter = new SimpleSyntaxHighlighter();
highlighterConfigurator.Configure(cli.Reader.Highlighter);
}
cli.Reader.UnregisterHandler(ConsoleKey.Escape);
cli.Reader.RegisterHandler(KeyHandler.FromAction((searchReaderContext) =>
{
TabCompletion tabCompletionInfo;
if (context.Definition.IsNonInteractive == false &&
context.Definition.Metadata.TryGetMeta<TabCompletion>(out tabCompletionInfo) &&
tabCompletionInfo.REPL == true)
{
// if this is an interactive REPL then continue the REPL in this case as the user may have changed their mind about taking
// this action - Note there are two places in this file that have this logic
throw new REPLContinueException();
}
else
{
throw new MissingArgException("The argument '" + context.CurrentArgument.DefaultAlias + "' is required", new ArgumentNullException(context.CurrentArgument.DefaultAlias));
}
}, ConsoleKey.Escape));
context.ArgumentValue = cli.PromptForLine("Enter value for " + context.CurrentArgument.DefaultAlias);
context.CurrentArgument.Populate(context);
return true;
}
else
{
return false;
}
}