Example #1
0
        private Dictionary <string, Type> InitializeVerbTypes(List <Type> verbTypes)
        {
            Dictionary <string, Type> res = new Dictionary <string, Type>(GetComparer());

            foreach (Type t in verbTypes)
            {
                object[] attrs = t.GetCustomAttributes(typeof(VerbAttribute), true);
                if (attrs.Length != 1)
                {
                    throw new ArgumentParserException(
                              String.Format(ExceptionMessages.VerbAttributeError, t.FullName));
                }

                VerbAttribute a = (VerbAttribute)attrs[0];
                if (res.ContainsKey(a.Name))
                {
                    throw new ArgumentParserException(
                              String.Format(ExceptionMessages.VerbDuplicate, t.FullName));
                }

                res.Add(a.Name, t);
            }

            return(res);
        }
Example #2
0
        public void PrintUsageInternal(List <Type> verbTypes, TextWriter output)
        {
            output.WriteLine("Syntax:");
            output.WriteLine();
            output.WriteLine("  {0} <verb> [-parameter <value>] [-option]", Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location));
            output.WriteLine();
            output.WriteLine("Verbs:");

            foreach (Type t in verbTypes)
            {
                VerbAttribute a = (VerbAttribute)t.GetCustomAttributes(typeof(VerbAttribute), true)[0];

                output.WriteLine("  {0}: {1}", a.Name, a.Description);
                output.WriteLine();
                output.WriteLine("    Parameters and options:");
                output.WriteLine();

                Dictionary <string, PropertyInfo>       pars;
                Dictionary <string, ParameterAttribute> atts;
                ReflectVerbType(t, out pars, out atts);

                foreach (string key in pars.Keys)
                {
                    if (atts[key] is OptionAttribute)
                    {
                        output.WriteLine(
                            "      -{0,-25}{1}",
                            atts[key].Name,
                            atts[key].Description);
                    }
                    else
                    {
                        output.WriteLine(
                            "      -{0,-25}{1}{2}",
                            String.Format("{0} <{1}>", atts[key].Name, pars[key].PropertyType.Name),
                            atts[key].Description,
                            atts[key].Required ? " Required." : "");
                    }
                }

                output.WriteLine();
            }
        }