private bool TryPreventExceptionWithPrompt(ArgHook.HookContext context) { if (parent.PromptIfMissing && ArgHook.HookContext.Current.Definition.IsNonInteractive == false) { var cli = new Cli(); 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); } context.ArgumentValue = cli.PromptForLine("Enter value for " + context.CurrentArgument.DefaultAlias); context.CurrentArgument.Populate(context); return(true); } else { return(false); } }
/// <summary> /// Prompts the user to enter a value for the given property in the case that the option was specified with no value /// </summary> /// <param name="context">the parser context</param> public override void BeforePopulateProperty(ArgHook.HookContext context) { if (context.ArgumentValue == string.Empty) { var cli = new Cli(); 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); } context.ArgumentValue = cli.PromptForLine("Enter value for " + context.CurrentArgument.DefaultAlias); } }
/// <summary> /// Prompts the user to enter a value for the given property in the case that the option was specified with no value /// </summary> /// <param name="context">the parser context</param> public override void BeforePopulateProperty(ArgHook.HookContext context) { if (context.ArgumentValue == string.Empty) { var cli = new Cli(); 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); } context.ArgumentValue = cli.PromptForLine("Enter value for " + context.CurrentArgument.DefaultAlias); } }
/// <summary> /// Validates that the user actually specified a value and optionally prompts them when it is missing. /// </summary> /// <param name="argument">The argument being populated. This validator doesn't do anything with it.</param> /// <param name="arg">The value specified on the command line or null if it wasn't specified</param> 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 Cli(); 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); } 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)); } }
private bool TryPreventExceptionWithPrompt(ArgHook.HookContext context) { if (parent.PromptIfMissing && ArgHook.HookContext.Current.Definition.IsNonInteractive == false) { var cli = new Cli(); 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); } context.ArgumentValue = cli.PromptForLine("Enter value for " + context.CurrentArgument.DefaultAlias); context.CurrentArgument.Populate(context); return true; } else { return false; } }
/// <summary> /// Validates that the user actually specified a value and optionally prompts them when it is missing. /// </summary> /// <param name="argument">The argument being populated. This validator doesn't do anything with it.</param> /// <param name="arg">The value specified on the command line or null if it wasn't specified</param> 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 Cli(); 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); } 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)); } }