Represents a valid command-line argument.
Example #1
0
        /// <summary>
        /// Parse the argument list using the
        /// </summary>
        /// <param name="args"></param>
        private void ParseArgumentList(string[] args)
        {
            if (args == null)
            {
                return;
            }

            foreach (string argument in args)
            {
                if (argument.Length == 0)
                {
                    continue;
                }
                switch (argument[0])
                {
                case '-':
                case '/':
                    int    endIndex = argument.IndexOfAny(new char[] { ':', '+', '-' }, 1);
                    string option   = argument.Substring(1, endIndex == -1 ? argument.Length - 1 : endIndex - 1);
                    string optionArgument;

                    if (option.Length + 1 == argument.Length)
                    {
                        optionArgument = null;
                    }
                    else if (argument.Length > 1 + option.Length && argument[1 + option.Length] == ':')
                    {
                        optionArgument = argument.Substring(option.Length + 2);
                    }
                    else
                    {
                        optionArgument = argument.Substring(option.Length + 1);
                    }

                    CommandLineArgument arg = _argumentCollection[option];
                    if (arg == null)
                    {
                        throw new CommandLineArgumentException(string.Format(CultureInfo.InvariantCulture,
                                                                             "Unknown argument '{0}'", argument));
                    }
                    else
                    {
                        // check if argument is obsolete
                        Attribute[] attribs = (Attribute[])arg.Property.GetCustomAttributes(
                            typeof(ObsoleteAttribute), false);
                        if (attribs.Length > 0)
                        {
                            ObsoleteAttribute obsoleteAttrib = (ObsoleteAttribute)attribs[0];
                            string            message        = string.Format(CultureInfo.InvariantCulture,
                                                                             ResourceUtils.GetString("NA1177"), option,
                                                                             obsoleteAttrib.Message);
                            if (obsoleteAttrib.IsError)
                            {
                                throw new CommandLineArgumentException(message);
                            }
                            else
                            {
                                Console.WriteLine(string.Empty);
                                Console.WriteLine("Warning: " + message);
                                Console.WriteLine(string.Empty);
                            }
                        }

                        if (arg.IsExclusive && args.Length > 1)
                        {
                            throw new CommandLineArgumentException(string.Format(CultureInfo.InvariantCulture,
                                                                                 "Commandline argument '-{0}' cannot be combined with other arguments.",
                                                                                 arg.LongName));
                        }
                        else
                        {
                            arg.SetValue(optionArgument);
                        }
                    }
                    break;

                case '@':
                    if (_supportsResponseFile)
                    {
                        string responseFile = argument.Substring(1, argument.Length - 1);
                        if (!File.Exists(responseFile))
                        {
                            throw new CommandLineArgumentException(string.Format(CultureInfo.InvariantCulture,
                                                                                 "Unable to open response file '{0}'.", responseFile));
                        }
                        // load file and parse it.
                        ProcessResponseFile(responseFile);
                        break;
                    }
                    continue;

                default:
                    if (_defaultArgument != null)
                    {
                        _defaultArgument.SetValue(argument);
                    }
                    else
                    {
                        throw new CommandLineArgumentException(string.Format(CultureInfo.InvariantCulture,
                                                                             "Unknown argument '{0}'", argument));
                    }
                    break;
                }
            }
        }
Example #2
0
 /// <summary>
 /// Removes a member from the collection.
 /// </summary>
 /// <param name="item">The <see cref="CommandLineArgument"/> to remove from the collection.</param>
 public void Remove(CommandLineArgument item)
 {
     base.List.Remove(item);
 }
Example #3
0
 /// <summary>
 /// Inserts a <see cref="CommandLineArgument"/> into the collection at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
 /// <param name="item">The <see cref="CommandLineArgument"/> to insert.</param>
 public void Insert(int index, CommandLineArgument item)
 {
     base.List.Insert(index, item);
 }
Example #4
0
 /// <summary>
 /// Retrieves the index of a specified <see cref="CommandLineArgument"/> object in the collection.
 /// </summary>
 /// <param name="item">The <see cref="CommandLineArgument"/> object for which the index is returned.</param>
 /// <returns>
 /// The index of the specified <see cref="CommandLineArgument"/>. If the <see cref="CommandLineArgument"/> is not currently a member of the collection, it returns -1.
 /// </returns>
 public int IndexOf(CommandLineArgument item)
 {
     return(base.List.IndexOf(item));
 }
Example #5
0
 /// <summary>
 /// Determines whether a <see cref="CommandLineArgument"/> is in the collection.
 /// </summary>
 /// <param name="item">The <see cref="CommandLineArgument"/> to locate in the collection.</param>
 /// <returns>
 /// <see langword="true" /> if <paramref name="item"/> is found in the
 /// collection; otherwise, <see langword="false" />.
 /// </returns>
 public bool Contains(CommandLineArgument item)
 {
     return(base.List.Contains(item));
 }
Example #6
0
 /// <summary>
 /// Adds a <see cref="CommandLineArgument"/> to the end of the collection.
 /// </summary>
 /// <param name="item">The <see cref="CommandLineArgument"/> to be added to the end of the collection.</param>
 /// <returns>The position into which the new element was inserted.</returns>
 public int Add(CommandLineArgument item)
 {
     return(base.List.Add(item));
 }