Beispiel #1
0
        private bool HandleHelp(string firstArg, object target)
        {
            var arg = firstArg;

            if (ArgumentPrefixes.Contains(firstArg[0].ToString()))
            {
                arg = firstArg.Substring(1);
            }

            Action <string> helpHandler = GetRegisteredHelpHandler(arg);

            if (helpHandler != null)
            {
                helpHandler(m_helpGenerator.GetHelp(this));

                return(true);
            }

            var definedHelpMethods = Type.GetMethodsWith <HelpAttribute>();

            foreach (var method in definedHelpMethods)
            {
                var att = method.GetAttribute <HelpAttribute>();

                var name = att.Name ?? method.Name;

                if (name.Equals(arg, StringComparison.InvariantCultureIgnoreCase) ||
                    att.Aliases.CommaSplit().Any(s => s.Equals(arg, StringComparison.InvariantCultureIgnoreCase)))
                {
                    try
                    {
                        VerifyMethodAndTarget(method, target);

                        var obj = method.IsStatic ? null : target;

                        MethodInvoker.Invoke(method, obj, new[] { m_helpGenerator.GetHelp(this) });

                        return(true);
                    }
                    catch (TargetParameterCountException ex)
                    {
                        throw new InvalidHelpHandlerException(method, ex);
                    }
                    catch (ArgumentException ex)
                    {
                        throw new InvalidHelpHandlerException(method, ex);
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
 /// <summary>
 /// Gets a help string that describes all the parser information for the user
 /// </summary>
 public string GetHelpString()
 {
     return(HelpGenerator.GetHelp(Types.Select(t => new ParserRunner(t, Register, HelpGenerator))));
 }