Пример #1
0
        /// <summary>
        /// Add one option which has long option only
        /// </summary>
        /// <param name="longOptName">Long option name</param>
        /// <param name="optType">Option type which indicates whether this option require an argument or not</param>
        /// <param name="description">Description for this option</param>
        /// <param name="metavar">Name of meta variable for this option (This value is used in <see cref="showUsage()"/>)</param>
        /// <param name="defaultValue">Default value of this option</param>
        public void Add(string longOptName, OptionType optType, string description = null, string metavar = null, string defaultValue = null)
        {
            var item = new OptionItem('\0', longOptName, optType, description, metavar, defaultValue);

            options.Add(item);
            longOptDict[longOptName] = item;
        }
Пример #2
0
        /// <summary>
        /// Add one option which has short option only
        /// </summary>
        /// <param name="shortOptName">Short option name</param>
        /// <param name="optType">Option type which indicates whether this option require an argument or not</param>
        /// <param name="description">Description for this option</param>
        /// <param name="metavar">Name of meta variable for this option (This value is used in <see cref="showUsage()"/>)</param>
        /// <param name="defaultValue">Default value of this option</param>
        public void Add(char shortOptName, OptionType optType, string description = null, string metavar = null, string defaultValue = null)
        {
            var item = new OptionItem(shortOptName, null, optType, description, metavar, defaultValue);

            options.Add(item);
            shortOptDict[shortOptName] = item;
        }
Пример #3
0
 /// <summary>
 /// Show description of a short option
 /// </summary>
 /// <param name="writer"><c>TextWriter</c> instance to output</param>
 /// <param name="item">Option item of short option</param>
 private void ShowShortOptionDescription(TextWriter writer, OptionItem item)
 {
     writer.Write("-" + item.ShortOptName);
     if (item.OptType != OptionType.NoArgument)
     {
         writer.Write(" " + item.Metavar);
     }
 }
Пример #4
0
        /// <summary>
        /// Generate default help option.
        /// </summary>
        public void AddHelp()
        {
            var item = new OptionItem('h', "help", OptionType.NoArgument, "Show help and exit this program", "", StringFalse);

            options.Add(item);
            shortOptDict['h']   = item;
            longOptDict["help"] = item;
        }
Пример #5
0
        /// <summary>
        /// Show description of a long option
        /// </summary>
        /// <param name="writer"><c>TextWriter</c> instance to output</param>
        /// <param name="item">Option item of long option</param>
        private void ShowLongOptionDescription(TextWriter writer, OptionItem item)
        {
            writer.Write("--" + item.LongOptName);
            switch (item.OptType)
            {
            case OptionType.OptionalArgument:
                writer.Write("[=" + item.Metavar + "]");
                break;

            case OptionType.RequiredArgument:
                writer.Write("=" + item.Metavar);
                break;
            }
        }