Ejemplo n.º 1
0
        private string GetUsage(CommandLineAttribute attr)
        {
            string usage = " ";

            if (attr is CommandLineValueAttribute)
            {
                CommandLineValueAttribute cattr = (CommandLineValueAttribute)attr;
                if (cattr.Place != -1)
                {
                    return(" <" + attr.Name + ">");
                }
            }
            if (attr.Optional)
            {
                usage += "[";
            }
            usage += "/" + attr.Name;
            if (attr.AlternateName != null)
            {
                usage += "|/" + attr.AlternateName;
            }
            if (attr is CommandLineValueAttribute)
            {
                usage += " <value>";
            }
            if (attr.Optional)
            {
                usage += "]";
            }
            return(usage);
        }
Ejemplo n.º 2
0
        private object GetArgument(object attrObject, string name, bool alternate)
        {
            object argumentValue      = null;
            CommandLineAttribute attr = (CommandLineAttribute)attrObject;

            if (attrObject is CommandLineValueAttribute)
            {
                CommandLineValueAttribute cattr = (CommandLineValueAttribute)attr;
                if (cattr.Place != -1)
                {
                    if (cattr.Place <= arguments.Length && !arguments[cattr.Place - 1].StartsWith("/") && !arguments[cattr.Place - 1].StartsWith("-"))
                    {
                        return(arguments[cattr.Place - 1]);
                    }
                    else
                    {
                        if (!cattr.Optional)
                        {
                            throw new CommandLineArgumentException("Missing parameters");
                        }
                    }
                }
                else
                {
                    argumentValue = GetArgumentValue(name);
                }
            }
            else
            {
                int index = GetArgumentIndex(name);
                if (attrObject is CommandLineFlagAttribute && index != -1)
                {
                    argumentValue = !arguments[index].EndsWith("-");
                }
            }
            if (argumentValue == null && alternate && attr.AlternateName != null)
            {
                return(GetArgument(attrObject, attr.AlternateName, false));
            }
            else
            {
                return(argumentValue);
            }
        }
Ejemplo n.º 3
0
        private string GetDescription(CommandLineAttribute attr)
        {
            string description = "\r\n";

            if (attr is CommandLineValueAttribute)
            {
                CommandLineValueAttribute cattr = (CommandLineValueAttribute)attr;
                if (cattr.Place != -1)
                {
                    description = "\r\n<" + attr.Name + ">";
                    return(description.PadRight(30) + attr.Description);
                }
            }
            description += "/" + attr.Name;
            if (attr is CommandLineValueAttribute)
            {
                description += " <value>";
            }
            description  = description.PadRight(30);
            description += attr.Description;
            return(description);
        }