예제 #1
0
파일: Command.cs 프로젝트: bordev/Tobasco
        internal CommandOption AddOption(string longName, string shortName, string description, Action <CommandOption> config)
        {
            var option = new CommandOption {
                LongName = longName, ShortName = shortName, Description = description
            };

            config(option);
            CommandOptions.Add(option);
            return(option);
        }
예제 #2
0
        /// <summary>
        /// Adds a new command option if none exists.  If one does exist then
        ///     the use switch is toggled on or of.
        /// </summary>
        /// <param name="name">The common name of the option.</param>
        /// <param name="value">The option value or command line switch
        ///     of the option.</param>
        /// <param name="on"><code>true</code> if the option should be
        ///     appended to the commandline, otherwise <code>false</code>.</param>
        protected void SetCommandOption(String name, String value, bool on)
        {
            Option option;

            if (CommandOptions.Contains(name))
            {
                option = (Option)CommandOptions[name];
            }
            else
            {
                option            = new Option();
                option.OptionName = name;
                option.Value      = value;
                CommandOptions.Add(name, option);
            }
            option.IfDefined = on;
        }
예제 #3
0
        public CommandLine(string[] commandLineArgs)
        {
            if (commandLineArgs == null)
            {
                throw new System.ArgumentNullException("commandLineArgs");
            }

            CommandOption currentOption = null;

            foreach (string arg in commandLineArgs)
            {
                if (arg.StartsWith("/"))
                {
                    // This is an option. Create it if it doesn't already exist (allow the same option to be
                    // specified twice - the values are appended in that case).

                    string optName = arg.Substring(1);

                    currentOption = m_options[optName];
                    if (currentOption == null)
                    {
                        currentOption = new CommandOption(optName);
                        m_options.Add(currentOption);
                    }
                }
                else
                {
                    // This is a value. Add it to the current option or to this object's values collection if
                    // it appears before any options.

                    if (currentOption == null)
                    {
                        m_values.Add(arg);
                    }
                    else
                    {
                        currentOption.Values.Add(arg);
                    }
                }
            }
        }