PowerArgs.ArgRequired.ValidateAlways C# (CSharp) Method

ValidateAlways() public method

Validates that the user actually specified a value and optionally prompts them when it is missing.
public ValidateAlways ( CommandLineArgument argument, string &arg ) : void
argument CommandLineArgument The argument being populated. This validator doesn't do anything with it.
arg string The value specified on the command line or null if it wasn't specified
return void
        public override void ValidateAlways(CommandLineArgument argument, ref string arg)
        {
            if (IsConditionallyRequired)
            {
                var matchingHook = (from h in argument.Metadata.Metas<ArgRequiredConditionalHook>() where h.parent == this select h).SingleOrDefault();
                if(matchingHook == null)
                {
                    argument.Metadata.Add(new ArgRequiredConditionalHook(this));
                }
            }

            if (IsConditionallyRequired == false && arg == null && 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 (ArgHook.HookContext.Current.Definition.IsNonInteractive == false &&
                        ArgHook.HookContext.Current.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 '" + argument.DefaultAlias + "' is required", new ArgumentNullException(argument.DefaultAlias));
                    }
                }, ConsoleKey.Escape));

                arg = cli.PromptForLine("Enter value for " + argument.DefaultAlias);
            }

            if (arg == null && IsConditionallyRequired == false)
            {
                throw new MissingArgException("The argument '" + argument.DefaultAlias + "' is required", new ArgumentNullException(argument.DefaultAlias));
            }
        }