Exemplo n.º 1
0
 internal static void RunAfterPopulateProperty(this PropertyInfo prop, ArgHook.HookContext context)
 {
     foreach (var hook in prop.GetHooks(h => h.AfterPopulatePropertyPriority))
     {
         hook.AfterPopulateProperty(context);
     }
 }
 /// <summary>
 /// Checks to see if the current argument is allowed to have a value based on which other arguments are present and based on the expression
 /// passed to the constructor.  If it's not allowed and has been specified then an UnexpectedArgException is thrown.
 /// </summary>
 /// <param name="context">The current PowerArgs processing context</param>
 public override void AfterPopulateProperties(ArgHook.HookContext context)
 {
     if (IsCurrentArgumentAllowed(context) == false && context.CurrentArgument.RevivedValue != null)
     {
         throw new UnexpectedArgException("The argument '" + context.CurrentArgument.DefaultAlias + "' cannot be used with one or more arguments: " + ExpressionText);
     }
 }
Exemplo n.º 3
0
        /// <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 (string.IsNullOrEmpty(context.ArgumentValue))
            {
                do
                {
                    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);
                    }

                    var result = cli.PromptForLine("Enter value for " + context.CurrentArgument.DefaultAlias);
                    result = result == "" ? null : result;
                    context.ArgumentValue = result;
                } while (KeepAsking && context.ArgumentValue == null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// If properties on the given object contain default value attributes then this method will initalize those properties with
        /// the right defaults
        /// </summary>
        /// <param name="o">the object to initialize</param>
        public static void InitializeDefaults(object o)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o cannot be null");
            }

            var def     = new CommandLineArgumentsDefinition(o.GetType());
            var context = new ArgHook.HookContext();

            context.Definition = def;
            context.Args       = o;

            foreach (var arg in def.Arguments)
            {
                context.ArgumentValue   = null;
                context.CurrentArgument = arg;
                context.RevivedProperty = null;
                if (arg.HasDefaultValue == false)
                {
                    continue;
                }

                arg.Populate(context);
            }

            def.SetPropertyValues(o);
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
 internal void Populate(ArgHook.HookContext context)
 {
     RunBeforePopulateProperty(context);
     Validate(ref context.ArgumentValue);
     Revive(context.ArgumentValue);
     RunAfterPopulateProperty(context);
 }
Exemplo n.º 7
0
        private void FindMatchingArgumentInRawParseData(ArgHook.HookContext context)
        {
            var match = from k in context.ParserData.ExplicitParameters.Keys where IsMatch(k) select k;

            if (match.Count() > 1)
            {
                throw new DuplicateArgException("Argument specified more than once: " + Aliases.First());
            }
            else if (match.Count() == 1)
            {
                var key = match.First();
                context.ArgumentValue = context.ParserData.ExplicitParameters[key];
                context.ParserData.ExplicitParameters.Remove(key);
            }
            else if (context.ParserData.ImplicitParameters.ContainsKey(Position))
            {
                var position = Position;
                context.ArgumentValue = context.ParserData.ImplicitParameters[position];
                context.ParserData.ImplicitParameters.Remove(position);
            }
            else
            {
                context.ArgumentValue = null;
            }
        }
 /// <summary>
 /// Unregisters the formatter
 /// </summary>
 /// <param name="context">The processing context</param>
 public override void AfterInvoke(ArgHook.HookContext context)
 {
     if (PipelineOutputFormatter.GetFormatter(targetType) == Formatter)
     {
         PipelineOutputFormatter.UnregisterFormatter(targetType);
     }
 }
Exemplo n.º 9
0
        private void PopulateProperties(ArgHook.HookContext context)
        {
            context.Args.GetType().RunBeforePopulateProperties(context);
            foreach (PropertyInfo prop in context.Args.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var match = from k in context.ParserData.ExplicitParameters.Keys
                            where prop.MatchesSpecifiedArg(k)
                            select k;

                if (match.Count() > 1)
                {
                    throw new DuplicateArgException("Argument specified more than once: " + prop.GetArgumentName());
                }

                if (match.Count() == 1)
                {
                    var key = match.First();
                    context.ArgumentValue = context.ParserData.ExplicitParameters[key];
                    context.ParserData.ExplicitParameters.Remove(key);
                }
                else
                {
                    if (prop.HasAttr <ArgPosition>() && context.ParserData.ImplicitParameters.ContainsKey(prop.Attr <ArgPosition>().Position))
                    {
                        var position = prop.Attr <ArgPosition>().Position;
                        context.ArgumentValue = context.ParserData.ImplicitParameters[position];
                        context.ParserData.ImplicitParameters.Remove(position);
                    }
                    else
                    {
                        context.ArgumentValue = null;
                    }
                }


                context.Property = prop;

                prop.RunBeforePopulateProperty(context);

                bool shouldValidateAndRevive = true;
                if (prop.Attr <ArgIgnoreAttribute>() != null)
                {
                    shouldValidateAndRevive = false;
                }
                if (prop.IsActionArgProperty() && ArgAction.GetActionProperty(context.Args.GetType()) != null)
                {
                    shouldValidateAndRevive = false;
                }

                if (shouldValidateAndRevive)
                {
                    prop.Validate(context);
                    prop.Revive(context.Args, context);
                }

                prop.RunAfterPopulateProperty(context);
            }
            context.Args.GetType().RunAfterPopulateProperties(context);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Makes sure the target is a boolean
 /// </summary>
 /// <param name="context">Context passed by the parser</param>
 public override void BeforePopulateProperty(ArgHook.HookContext context)
 {
     base.BeforePopulateProperty(context);
     if (context.CurrentArgument.ArgumentType != typeof(bool))
     {
         throw new InvalidArgDefinitionException(typeof(HelpHook).Name + " attributes can only be used with boolean properties or parameters");
     }
 }
Exemplo n.º 11
0
 internal static void PopulateArguments(List <CommandLineArgument> arguments, ArgHook.HookContext context)
 {
     foreach (var argument in arguments)
     {
         argument.FindMatchingArgumentInRawParseData(context);
         argument.Populate(context);
     }
 }
Exemplo n.º 12
0
        internal static void Revive(this PropertyInfo prop, object toRevive, ArgHook.HookContext context)
        {
            if (ArgRevivers.CanRevive(prop.PropertyType) && context.ArgumentValue != null)
            {
                try
                {
                    if (prop.PropertyType.IsEnum)
                    {
                        bool ignoreCase = true;

                        if (prop.HasAttr <ArgIgnoreCase>() && prop.Attr <ArgIgnoreCase>().IgnoreCase == false)
                        {
                            ignoreCase = true;
                        }

                        context.RevivedProperty = ArgRevivers.ReviveEnum(prop.PropertyType, context.ArgumentValue, ignoreCase);
                    }
                    else
                    {
                        context.RevivedProperty = ArgRevivers.Revive(prop.PropertyType, prop.GetArgumentName(), context.ArgumentValue);
                    }
                    prop.SetValue(toRevive, context.RevivedProperty, null);
                }
                catch (ArgException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null && ex.InnerException is ArgException)
                    {
                        throw ex.InnerException;
                    }
                    else
                    {
                        if (prop.PropertyType.IsEnum)
                        {
                            throw new ArgException("'" + context.ArgumentValue + "' is not a valid value for " + prop.GetArgumentName() + ". Available values are [" + string.Join(", ", Enum.GetNames(prop.PropertyType)) + "]", ex);
                        }
                        else
                        {
                            throw new ArgException(ex.Message, ex);
                        }
                    }
                }
            }
            else if (ArgRevivers.CanRevive(prop.PropertyType) && prop.PropertyType == typeof(SecureStringArgument))
            {
                context.RevivedProperty = ArgRevivers.Revive(prop.PropertyType, prop.GetArgumentName(), context.ArgumentValue);
                prop.SetValue(toRevive, context.RevivedProperty, null);
            }
            else if (context.ArgumentValue != null)
            {
                throw new ArgException("Unexpected argument '" + prop.GetArgumentName() + "' with value '" + context.ArgumentValue + "'");
            }
        }
Exemplo n.º 13
0
 internal static void PopulateArguments(List <CommandLineArgument> arguments, ArgHook.HookContext context)
 {
     foreach (var argument in arguments)
     {
         argument.FindMatchingArgumentInRawParseData(context);
         argument.RunBeforePopulateProperty(context);
         argument.Validate(ref context.ArgumentValue);
         argument.Revive(context.ArgumentValue);
         argument.RunAfterPopulateProperty(context);
     }
 }
Exemplo n.º 14
0
        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);

                var property = context.CurrentArgument.Source as PropertyInfo;
                if (property != null && context.Args != null)
                {
                    property.SetValue(context.Args, context.CurrentArgument.RevivedValue, null);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 15
0
        private static T DoStandardExceptionHandling<T>(ArgException ex, ArgHook.HookContext context, CommandLineArgumentsDefinition definition) where T : class
        {
            Console.WriteLine(ex.Message);

            ArgUsage.GetStyledUsage(definition, definition.ExceptionBehavior.ExeName, new ArgUsageOptions
            {
                ShowPosition = definition.ExceptionBehavior.ShowPositionColumn,
                ShowType = definition.ExceptionBehavior.ShowTypeColumn,
                ShowPossibleValues = definition.ExceptionBehavior.ShowPossibleValues,
            }).Write();

            return CreateEmptyResult<T>(context, ex);
        }
Exemplo n.º 16
0
        internal void RunArgumentHook(ArgHook.HookContext context, Func <ArgHook, int> orderby, Action <ArgHook> hookAction)
        {
            context.Property        = Source as PropertyInfo;
            context.CurrentArgument = this;

            foreach (var hook in Hooks.OrderBy(orderby))
            {
                hookAction(hook);
            }

            context.Property        = null;
            context.CurrentArgument = null;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Writes the help as long as WriteHelp is true
        /// </summary>
        /// <param name="context">Context passed by the parser</param>
        public override void AfterCancel(ArgHook.HookContext context)
        {
            base.AfterCancel(context);

            if (WriteHelp == false)
            {
                return;
            }
            var usage = UsageTemplateProvider.GetUsage(UsageTemplateProviderType, context.Definition);

            usage.Write();
            FireUsageWritten(usage);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Before PowerArgs parses the args, this hook inspects the command line for the indicator and if found
        /// takes over the command line and provides tab completion.
        /// </summary>
        /// <param name="context">The context used to inspect the command line arguments.</param>
        public override void BeforeParse(ArgHook.HookContext context)
        {
            if (indicator == "" && context.CmdLineArgs.Length != 0)
            {
                return;
            }
            else if (indicator != "" && (context.CmdLineArgs.Length != 1 || context.CmdLineArgs[0] != indicator))
            {
                return;
            }

            try
            {
                // This is a little hacky, but I could not find a better way to make the tab completion start on the same lime
                // as the command line input

                var color    = Console.ForegroundColor;
                var lastLine = ConsoleHelper.StdConsoleProvider.ReadALineOfConsoleOutput(Console.CursorTop - 1);
                Console.CursorTop--;
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(lastLine);
                Console.ForegroundColor = color;
                Console.CursorTop--;
                Console.CursorLeft = lastLine.Length + 1;
            }
            catch (Exception)
            {
                Console.Write(indicator + "> ");
            }

            List <string> completions = FindTabCompletions(context.Args.GetType());

            List <ITabCompletionSource> completionSources = new List <ITabCompletionSource>();

            if (this.completionSource != null)
            {
                completionSources.Add((ITabCompletionSource)Activator.CreateInstance(this.completionSource));
            }
            completionSources.Add(new SimpleTabCompletionSource(completions)
            {
                MinCharsBeforeCyclingBegins = 0
            });
            completionSources.Add(new FileSystemTabCompletionSource());

            string str = null;

            context.CmdLineArgs = ConsoleHelper.ReadLine(ref str, LoadHistory(), new MultiTabCompletionSource(completionSources));
            AddToHistory(str);
        }
Exemplo n.º 19
0
        private void Evaluate(ArgHook.HookContext context, string expressionText, bool not)
        {
            try
            {
                var newExpressionText = expressionText;
                if (not)
                {
                    newExpressionText = "!(" + expressionText + ")";
                }

                var expression = BooleanExpressionParser.Parse(newExpressionText);
                var eval       = expression.Evaluate(context.Definition.CreateVariableResolver());

                if (not)
                {
                    if (eval == true && context.CurrentArgument.RevivedValue == null)
                    {
                        if (TryPreventExceptionWithPrompt(context) == false)
                        {
                            throw new MissingArgException("The argument '" + context.CurrentArgument.DefaultAlias + "' is required if the following argument(s) are not specified: " + expressionText);
                        }
                    }
                }
                else
                {
                    if (eval == true && context.CurrentArgument.RevivedValue == null)
                    {
                        if (TryPreventExceptionWithPrompt(context) == false)
                        {
                            throw new MissingArgException("The argument '" + context.CurrentArgument.DefaultAlias + "' is required if the following argument(s) are specified: " + expressionText);
                        }
                    }
                }
            }
            catch (MissingArgException)
            {
                throw;
            }
            catch (REPLContinueException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var targetText = context.CurrentArgument.DefaultAlias + " (" + expressionText + ")";
                throw new InvalidArgDefinitionException("Failed to evaluate conditional ArgRequired clause on target '" + targetText + "'" + ex.Message);
            }
        }
Exemplo n.º 20
0
        private static T DoStandardExceptionHandling <T>(ArgException ex, ArgHook.HookContext context, CommandLineArgumentsDefinition definition) where T : class
        {
            Console.WriteLine(ex.Message);

            if (definition.ExceptionBehavior.UsageTemplateFile != null)
            {
                var template = File.ReadAllText(definition.ExceptionBehavior.UsageTemplateFile);
                ArgUsage.GenerateUsageFromTemplate(definition, template).Write();
            }
            else
            {
                UsageTemplateProvider.GetUsage(definition.ExceptionBehavior.UsageTemplateProviderType, definition).Write();
            }

            return(CreateEmptyResult <T>(context, ex));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Writes the help as long as WriteHelp is true
        /// </summary>
        /// <param name="context">Context passed by the parser</param>
        public override void AfterCancel(ArgHook.HookContext context)
        {
            base.AfterCancel(context);

            if (WriteHelp == false)
            {
                return;
            }

            ArgUsage.GetStyledUsage(context.Definition, EXEName, new ArgUsageOptions()
            {
                ShowPosition       = ShowPositionColumn,
                ShowType           = ShowTypeColumn,
                ShowPossibleValues = ShowPossibleValues,
            }).Write();
        }
Exemplo n.º 22
0
        internal static void RunBeforeParse(this Type t, ArgHook.HookContext context)
        {
            foreach (var hook in t.GetHooks(h => h.BeforeParsePriority))
            {
                hook.BeforeParse(context);
            }

            foreach (var arg in t.GetArguments())
            {
                foreach (var hook in arg.GetHooks(h => h.BeforeParsePriority))
                {
                    context.Property = arg;
                    hook.BeforeParse(context);
                    context.Property = null;
                }
            }
        }
Exemplo n.º 23
0
        internal void Populate(ArgHook.HookContext context)
        {
            RunBeforePopulateProperty(context);

            if (RevivedValueOverride == null)
            {
                Validate(ref context.ArgumentValue);
                Revive(context.ArgumentValue);
            }
            else
            {
                RevivedValue         = RevivedValueOverride;
                RevivedValueOverride = null;
            }

            RunAfterPopulateProperty(context);
        }
Exemplo n.º 24
0
 internal void Validate(ArgHook.HookContext context)
 {
     context.RunBeforeValidateDefinition();
     ValidateArguments(Arguments);
     ValidateActionAliases();
     foreach (var action in Actions)
     {
         if (action.Aliases.Count == 0)
         {
             throw new InvalidArgDefinitionException("One of your actions has no aliases");
         }
         ValidateArguments(Arguments.Union(action.Arguments));
         if (action.ActionMethod == null)
         {
             throw new InvalidArgDefinitionException("The action '" + action.DefaultAlias + "' has no ActionMethod defined");
         }
     }
 }
Exemplo n.º 25
0
        internal static void PopulateArguments(List <CommandLineArgument> arguments, ArgHook.HookContext context)
        {
            var oldCurrent = context.CurrentArgument;

            try
            {
                foreach (var argument in arguments)
                {
                    context.CurrentArgument = argument;
                    argument.FindMatchingArgumentInRawParseData(context);
                    argument.Populate(context);
                }
            }
            finally
            {
                context.CurrentArgument = oldCurrent;
            }
        }
Exemplo n.º 26
0
        internal static void Validate(this PropertyInfo prop, ArgHook.HookContext context)
        {
            if (prop.PropertyType == typeof(SecureStringArgument) && prop.Attrs <ArgValidator>().Count > 0)
            {
                throw new InvalidArgDefinitionException("Properties of type SecureStringArgument cannot be validated.  If your goal is to make the argument required then the[ArgRequired] attribute is not needed.  The SecureStringArgument is designed to prompt the user for a value only if your code asks for it after parsing.  If your code never reads the SecureString property then the user is never prompted and it will be treated as an optional parameter.  Although discouraged, if you really, really need to run custom logic against the value before the rest of your program runs then you can implement a custom ArgHook, override RunAfterPopulateProperty, and add your custom attribute to the SecureStringArgument property.");
            }

            foreach (var v in prop.Attrs <ArgValidator>().OrderByDescending(val => val.Priority))
            {
                if (v.ImplementsValidateAlways)
                {
                    v.ValidateAlways(prop, ref context.ArgumentValue);
                }
                else if (context.ArgumentValue != null)
                {
                    v.Validate(prop.GetArgumentName(), ref context.ArgumentValue);
                }
            }
        }
Exemplo n.º 27
0
        private ArgAction ParseInternal(Type t, string[] input)
        {
            ArgShortcut.RegisterShortcuts(t);
            ValidateArgScaffold(t);

            var context = new ArgHook.HookContext();

            context.Args        = Activator.CreateInstance(t);
            context.CmdLineArgs = input;

            t.RunBeforeParse(context);
            var specifiedActionProperty = FindSpecifiedAction(t, ref context.CmdLineArgs);

            context.ParserData = ArgParser.Parse(context.CmdLineArgs);
            PopulateProperties(context);

            if (specifiedActionProperty != null)
            {
                var actionPropertyValue = Activator.CreateInstance(specifiedActionProperty.PropertyType);
                var toRestore           = context.Args;
                context.Args = actionPropertyValue;
                PopulateProperties(context);
                context.Args = toRestore;
                specifiedActionProperty.SetValue(context.Args, actionPropertyValue, null);
            }

            if (context.ParserData.ImplicitParameters.Count > 0)
            {
                throw new UnexpectedArgException("Unexpected unnamed argument: " + context.ParserData.ImplicitParameters.First().Value);
            }

            if (context.ParserData.ExplicitParameters.Count > 0)
            {
                throw new UnexpectedArgException("Unexpected named argument: " + context.ParserData.ExplicitParameters.First().Key);
            }

            return(new ArgAction()
            {
                Value = context.Args,
                ActionArgs = specifiedActionProperty != null?specifiedActionProperty.GetValue(context.Args, null) : null,
                                 ActionArgsProperty = specifiedActionProperty
            });
        }
Exemplo n.º 28
0
        internal static void RunAfterPopulateProperties(this Type t, ArgHook.HookContext context)
        {
            foreach (var hook in t.GetHooks(h => h.AfterPopulatePropertiesPriority))
            {
                hook.AfterPopulateProperties(context);
            }

            var toRestore = context.Property;

            foreach (PropertyInfo prop in t.GetProperties())
            {
                context.Property = prop;
                foreach (var hook in prop.GetHooks(h => h.AfterPopulatePropertiesPriority))
                {
                    hook.AfterPopulateProperties(context);
                }
            }
            context.Property = toRestore;
        }
Exemplo n.º 29
0
 public override void AfterPopulateProperties(ArgHook.HookContext context)
 {
     if (parent.If != null && parent.IfNot != null)
     {
         throw new InvalidArgDefinitionException("You cannot specify both the 'If' and the 'IfNot' properties on the ArgRequired metadata");
     }
     else if (parent.If != null)
     {
         Evaluate(context, parent.If, false);
     }
     else if (parent.IfNot != null)
     {
         Evaluate(context, parent.IfNot, true);
     }
     else
     {
         throw new InvalidOperationException("ArgRequired could not determine if the given argument was required.  This is likely a bug in PowerArgs.");
     }
 }
Exemplo n.º 30
0
        private bool TryPreventExceptionWithPrompt(ArgHook.HookContext context)
        {
            if (parent.PromptIfMissing && ArgHook.HookContext.Current.Definition.IsNonInteractive == false)
            {
                var value = "";
                while (string.IsNullOrWhiteSpace(value))
                {
                    Console.Write("Enter value for " + context.CurrentArgument.DefaultAlias + ": ");
                    value = Console.ReadLine();
                }

                context.ArgumentValue = value;
                context.CurrentArgument.Populate(context);
                return(true);
            }
            else
            {
                return(false);
            }
        }