/// <summary> /// When main argument is present, tests, whether arguments required by main argument are also present. /// If not <see cref="MandatoryArgumentNotSetException"/> is thrown. /// </summary> /// <param name="parser">parser object gives access to the defined arguments, their values and /// parameters of the parser</param> /// <exception cref="MandatoryArgumentNotSetException">Thrown when main argument is present but some of the arguments /// required for main argument is not.</exception> public override void Certify(CommandLineParser parser) { if (_argumentsRequiredForMainArgument == null || _mainArgument == null) { _argumentsRequiredForMainArgument = ArgumentGroupCertification.GetArgumentsFromGroupString(parser, _argumentsRequiredForMainArgumentString); _mainArgument = ArgumentGroupCertification.GetArgumentsFromGroupString(parser, _mainArgumentString).SingleOrDefault(); } if (_argumentsRequiredForMainArgument.Length == 0) { throw new InvalidArgumentGroupException( "Argument group is empty. Argument group must have at least one member."); } if (Description == null) { Description = DefaultUsageDescription(); } if (_mainArgument.Parsed) { foreach (Argument requiredArgument in _argumentsRequiredForMainArgument) { if (!requiredArgument.Parsed) { throw new MandatoryArgumentNotSetException(String.Format(Messages.EXC_GROUP_DISTINCT, _mainArgumentString, _argumentsRequiredForMainArgumentString), requiredArgument.Name); } } } }
/// <summary> /// Creates new instance of DistinctGroupsCertification - this certification specifies two groups of arguments, that /// can not be used together. /// </summary> /// <param name="argumentGroup1">first group of arguments</param> /// <param name="argumentGroup2">second group of arguments</param> public DistinctGroupsCertification(Argument[] argumentGroup1, Argument[] argumentGroup2) { _argumentGroup1 = argumentGroup1; _argumentGroup2 = argumentGroup2; _argumentGroupString1 = ArgumentGroupCertification.GetGroupStringFromArguments(argumentGroup1); _argumentGroupString2 = ArgumentGroupCertification.GetGroupStringFromArguments(argumentGroup2); }
/// <summary> /// Creates new instance of ArgumentRequiresOtherArgumentsCertification - this certification allows to define a /// group of arguments required for another argument. /// </summary> /// <param name="mainArgument"></param> /// <param name="argumentsRequiredForMainArgument"></param> public ArgumentRequiresOtherArgumentsCertification(Argument mainArgument, Argument[] argumentsRequiredForMainArgument) { _argumentsRequiredForMainArgument = argumentsRequiredForMainArgument; _argumentsRequiredForMainArgumentString = ArgumentGroupCertification.GetGroupStringFromArguments(argumentsRequiredForMainArgument); _mainArgumentString = ArgumentGroupCertification.GetGroupStringFromArguments(new[] { mainArgument }); if (_description == null) { _description = DefaultUsageDescription(); } }
/// <summary> /// Creates new instance of DistinctGroupsCertification - this certification specifies two groups of arguments, that /// can not be used together. /// </summary> /// <param name="argumentGroup1">first group of arguments</param> /// <param name="argumentGroup2">second group of arguments</param> public DistinctGroupsCertification(Argument[] argumentGroup1, Argument[] argumentGroup2) { _argumentGroup1 = argumentGroup1; _argumentGroup2 = argumentGroup2; _argumentGroupString1 = ArgumentGroupCertification.GetGroupStringFromArguments(argumentGroup1); _argumentGroupString2 = ArgumentGroupCertification.GetGroupStringFromArguments(argumentGroup2); if (_description == null) { _description = DefaultUsageDescription(); } }
/// <summary> /// Tests, whether some arguments from both groups are not used. If so, ArgumentConflictException is thrown. /// </summary> /// <param name="parser">parser object gives access to the defined arguments, their values and /// parameters of the parser</param> /// <exception cref="ArgumentConflictException">Thrown when arguments from both groups are used</exception> /// <exception cref="InvalidArgumentGroupException">Thrown when one of the groups is empty</exception> public override void Certify(CommandLineParser parser) { if (_argumentGroup1 == null || _argumentGroup2 == null) { _argumentGroup1 = ArgumentGroupCertification.GetArgumentsFromGroupString(parser, _argumentGroupString1); _argumentGroup2 = ArgumentGroupCertification.GetArgumentsFromGroupString(parser, _argumentGroupString2); } if (_argumentGroup1.Length == 0 || _argumentGroup1.Length == 0) { throw new InvalidArgumentGroupException( "Argument group is empty. Argument group must have at least one member."); } int used1 = 0; int used2 = 0; foreach (Argument argument in _argumentGroup1) { if (argument.Parsed) { used1++; } } foreach (Argument argument in _argumentGroup2) { if (argument.Parsed) { used2++; } } if (used1 > 0 && used2 > 0) { throw new ArgumentConflictException(String.Format(Messages.EXC_GROUP_DISTINCT, _argumentGroupString1, _argumentGroupString2)); } if (Description == null) { Description = DefaultUsageDescription(); } }