コード例 #1
0
ファイル: DefaultParser.cs プロジェクト: jwerba/cli4net
        /**
         * Sets the values of Options using the values in <code>properties</code>.
         *
         * @param properties The value properties to be processed.
         */
        private void HandleProperties(Dictionary <string, string> properties)
        {
            if (properties == null)
            {
                return;
            }

            foreach (var prop in properties)
            {
                string option = prop.Key;
                Option opt    = options.GetOption(option);
                if (opt == null)
                {
                    throw new UnrecognizedOptionException("Default option wasn't defined", option);
                }
                // if the option is part of a group, check if another option of the group has been selected
                OptionGroup group    = options.GetOptionGroup(opt);
                bool        selected = group != null && group.GetSelected() != null;
                if (!cmd.HasOption(option) && !selected)
                {
                    // get the value from the properties
                    string value = properties[option];

                    if (opt.HasArg())
                    {
                        if (opt.GetValues() == null || opt.GetValues().Length == 0)
                        {
                            opt.AddValueForProcessing(value);
                        }
                    }
                    else if (!("yes".Equals(value.ToLower()) ||
                               "true".Equals(value.ToLower()) ||
                               "1".Equals(value.ToLower())))
                    {
                        // if the value is not yes, true or 1 then don't add the option to the CommandLine
                        continue;
                    }
                    HandleOption(opt);
                    currentOption = null;
                }
            }
        }
コード例 #2
0
 /**
  * Construct a new <code>AlreadySelectedException</code>
  * for the specified option group.
  *
  * @param group  the option group already selected
  * @param option the option that triggered the exception
  * @since 1.2
  */
 public AlreadySelectedException(OptionGroup group, Option option) : base("The option '" + option.GetKey() + "' was specified but an option from this group "
                                                                          + "has already been selected: '" + group.GetSelected() + "'")
 {
     this.group  = group;
     this.option = option;
 }