Beispiel #1
0
 private static void MakeRemainingUsageString(MemberAttribute consumeRemaining, StringBuilder usage)
 {
     if (consumeRemaining != null)
         if (consumeRemaining.AltName != null)
             usage.AppendFormat(" [<{0}> ...]", consumeRemaining.AltName);
         else
             usage.Append(" [...]");
 }
Beispiel #2
0
 private void ParseOptionalArgumentWithOptionalArgument(string argName, MemberAttribute handler)
 {
     if (_argIt.MoveNext() == true)
     {
         MemberSetter.SetArg(_t, handler, _argIt.Current);
     }
     else
     {
         throw new Exception(string.Format("Missing value for argument for {0}", argName));
     }
 }
Beispiel #3
0
        public static string GetUsageString(string progName, IEnumerable<MemberAttribute> optional, IEnumerable<MemberAttribute> required, MemberAttribute consumeRemaining)
        {
            var usage = new StringBuilder("Usage: ");

            usage.Append(progName);

            MakeOptionalUsageString(optional, usage);
            MakeRequiredUsageString(required, usage);
            MakeRemainingUsageString(consumeRemaining, usage);

            return usage.ToString();
        }
Beispiel #4
0
        public static void SetArg <T>(T t, MemberAttribute arg, string value)
        {
            if (arg.AllowedValues != null)
            {
                if (arg.AllowedValues.Contains(value) == false)
                {
                    throw new FormatException(string.Format("Not an allowed value:{0}", value));
                }
            }

            SetImpl(t, arg, value);
        }
Beispiel #5
0
 private static void MakeRemainingUsageString(MemberAttribute consumeRemaining, StringBuilder usage)
 {
     if (consumeRemaining != null)
     {
         if (consumeRemaining.AltName != null)
         {
             usage.AppendFormat(" [<{0}> ...]", consumeRemaining.AltName);
         }
         else
         {
             usage.Append(" [...]");
         }
     }
 }
Beispiel #6
0
        public ArgParser(string progName)
        {
            _progName = progName;

            var attrs = GetAttributes();

            _optionalArgumentAttrs = from member in attrs where member.IsOptional == true && member.IsConsumeRemaining == false orderby member.Rank select member;
            _requiredArgumentAttrs = from member in attrs where member.IsOptional == false orderby member.Rank select member;
            IEnumerable <MemberAttribute> remainingArgumentAttrs = from member in attrs where member.IsOptional == true && member.IsConsumeRemaining == true orderby member.Rank select member;

            if (remainingArgumentAttrs.Any())
            {
                _remainingArgumentAttr = remainingArgumentAttrs.First();
            }
        }
Beispiel #7
0
        private void ParseOptionalArgument()
        {
            string argName = ParseOptionalArgName(_argIt.Current);

            MemberAttribute handler = FindMatchingOptionOrThrow(argName);

            if (handler.HasOptionalArgument == false)
            {
                MemberSetter.SetOptionalFlagArg(_t, handler, true);
            }
            else
            {
                ParseOptionalArgumentWithOptionalArgument(argName, handler);
            }
        }
Beispiel #8
0
 public static void SetImpl <T, U>(T t, MemberAttribute arg, U value)
 {
     if (arg.MemberInfo is FieldInfo)
     {
         SetFieldWithArg((FieldInfo)arg.MemberInfo, t, value);
     }
     else if (arg.MemberInfo is PropertyInfo)
     {
         SetPropertyWithArg((PropertyInfo)arg.MemberInfo, t, value);
     }
     else if (arg.MemberInfo is MethodInfo)
     {
         SetMethodWithArg((MethodInfo)arg.MemberInfo, t, value);
     }
     else
     {
         throw new NotImplementedException("Unsupported member type");
     }
 }
Beispiel #9
0
        public static string GetUsageString(string progName, IEnumerable <MemberAttribute> optional, IEnumerable <MemberAttribute> required, MemberAttribute consumeRemaining)
        {
            var usage = new StringBuilder("Usage: ");

            usage.Append(progName);

            MakeOptionalUsageString(optional, usage);
            MakeRequiredUsageString(required, usage);
            MakeRemainingUsageString(consumeRemaining, usage);

            return(usage.ToString());
        }
 public RemainingArgumentsParser(T t, MemberAttribute remaining, ArgIterator argIt)
 {
     _t         = t;
     _remaining = remaining;
     _argIt     = argIt;
 }
Beispiel #11
0
 public static void SetRemainingArg <T>(T t, MemberAttribute arg, string[] value)
 {
     SetImpl(t, arg, value);
 }
Beispiel #12
0
 public static void SetOptionalFlagArg <T>(T t, MemberAttribute arg, bool value)
 {
     SetImpl(t, arg, value);
 }