private static string GetArgumentName(Action action)
 {
     if (action == null) return null;
     if (action.OptionStrings.IsTrue())
         return string.Format("({0})", string.Join("/", action.OptionStrings));
     if (!string.IsNullOrWhiteSpace(action.MetaVariable))
         return action.MetaVariable;
     if (action.HasDestination && action.HasValidDestination)
         return action.Destination;
     return null;
 }
Пример #2
0
 public ArgumentActionConstraint(Action expected) : base(expected)
 {
 }
Пример #3
0
 public void AreEqual(Action action1, Action action2)
 {
     Assert.That(action2, new ArgumentActionConstraint(action1));
 }
Пример #4
0
        private void HandleConflictWithResolve(Action action,
            IEnumerable<KeyValuePair<string, Action>> conflictingActions)
        {
            //remove all conflicting options
            foreach (var kv in conflictingActions)
            {
                kv.Value.OptionStrings.Remove(kv.Key);
                OptionStringActions.Remove(kv.Key);

                //if the option now has no option string, remove it from the container holding it
                if (!kv.Value.OptionStrings.Any())
                    kv.Value.Container.RemoveAction(kv.Value);
            }
        }
Пример #5
0
 private void HandleConflictWithError(Action action,
     IEnumerable<KeyValuePair<string, Action>> conflictingActions)
 {
     List<string> conflictionOptions = conflictingActions.Select(it => it.Key).ToList();
     string conflictString = string.Join(", ", conflictionOptions);
     if (conflictionOptions.Count == 1)
         throw new ParserException(string.Format("Confliction option string: {0}", conflictString));
     throw new ParserException(string.Format("Confliction option strings: {0}", conflictString));
 }
Пример #6
0
 public void CheckConflict(Action action)
 {
     var conflOptionals = new List<KeyValuePair<string, Action>>();
     foreach (string optionString in action.OptionStrings)
     {
         Action conflOptional;
         if (OptionStringActions.TryGetValue(optionString, out conflOptional))
             conflOptionals.Add(new KeyValuePair<string, Action>(optionString, conflOptional));
     }
     if (!conflOptionals.Any()) return;
     Action<Action, IEnumerable<KeyValuePair<string, Action>>> confictHandler = GetConflictHandler();
     confictHandler(action, conflOptionals);
 }
Пример #7
0
 public virtual void RemoveAction(Action action)
 {
     Actions.Remove(action);
 }
Пример #8
0
        public virtual Action AddAction(Action action)
        {
            if (ReferenceEquals(action, null))
                throw new ArgumentNullException("action");
            CheckConflict(action);

            Actions.Add(action);
            action.Container = this;

            foreach (string optionString in action.OptionStrings)
                OptionStringActions[optionString] = action;

            if (!HasNegativeNumberOptionals.IsTrue() &&
                action.OptionStrings.Any(optionString => NegativeNumberMatcher.IsMatch(optionString)))
                HasNegativeNumberOptionals.Add(true);
            return action;
        }
Пример #9
0
 public UnknownParserException(Action action, string parserName)
     : base(action, string.Format("Unknown parser {0}", parserName))
 {
     ParserName = parserName;
 }
Пример #10
0
 public override void RemoveAction(Action action)
 {
     base.RemoveAction(action);
     GroupActions.Remove(action);
 }
Пример #11
0
 public override Action AddAction(Action action)
 {
     Action res = base.AddAction(action);
     GroupActions.Add(res);
     return res;
 }
Пример #12
0
 public InvalideChoiceException(Action action, object value)
     : base(action, string.Format("Invalid choice: {0}", value))
 {
     Value = value;
 }
Пример #13
0
 public override Action AddAction(Action action)
 {
     if (action.IsRequired)
         throw new ParserException("Mutually exclusive arguments must be optional");
     return base.AddAction(action);
 }