示例#1
0
 public Options(string[] args,
                OptionsParsingMode parsingMode,
                bool breakSingleDashManyLettersIntoManyOptions,
                bool endOptionProcessingWithDoubleDash,
                bool dontSplitOnCommas,
                ErrorReporter reportError)
 {
     ParsingMode = parsingMode;
     BreakSingleDashManyLettersIntoManyOptions = breakSingleDashManyLettersIntoManyOptions;
     EndOptionProcessingWithDoubleDash         = endOptionProcessingWithDoubleDash;
     DontSplitOnCommas = dontSplitOnCommas;
     if (reportError == null)
     {
         ReportError = new ErrorReporter(DefaultErrorReporter);
     }
     else
     {
         ReportError = reportError;
     }
     InitializeOtherDefaults();
     if (args != null)
     {
         ProcessArgs(args);
     }
 }
示例#2
0
 public Options(string[] args,
                OptionsParsingMode parsingMode,
                bool breakSingleDashManyLettersIntoManyOptions,
                bool endOptionProcessingWithDoubleDash,
                bool dontSplitOnCommas) :
     this(args, OptionsParsingMode.Both, false, true, false, null)
 {
 }
示例#3
0
        public Options(string[] args, 
					   OptionsParsingMode parsingMode, 
					   bool breakSingleDashManyLettersIntoManyOptions, 
					   bool endOptionProcessingWithDoubleDash,
					   bool dontSplitOnCommas)
            : this(args, OptionsParsingMode.Both, false, true, false, null)
        {
        }
示例#4
0
        public OptionList(Options optionBundle)
        {
            if (optionBundle == null)
            {
                throw new ArgumentNullException("optionBundle");
            }

            Type optionsType = optionBundle.GetType();

            this.optionBundle = optionBundle;
            this.parsingMode  = optionBundle.ParsingMode;
            this.breakSingleDashManyLettersIntoManyOptions = optionBundle.BreakSingleDashManyLettersIntoManyOptions;
            this.endOptionProcessingWithDoubleDash         = optionBundle.EndOptionProcessingWithDoubleDash;
            this.ReportError = optionBundle.ReportError;

            ExtractEntryAssemblyInfo(optionsType);

            foreach (MemberInfo mi in optionsType.GetMembers())
            {
                object[] attribs = mi.GetCustomAttributes(typeof(KillOptionAttribute), true);
                if (attribs == null || attribs.Length == 0)
                {
                    attribs = mi.GetCustomAttributes(typeof(OptionAttribute), true);
                    if (attribs != null && attribs.Length > 0)
                    {
                        OptionDetails option = new OptionDetails(mi, (OptionAttribute)attribs[0], optionBundle);
                        list.Add(option);
                        HasSecondLevelHelp = HasSecondLevelHelp || option.SecondLevelHelp;
                    }
                    else if (mi.DeclaringType == mi.ReflectedType)                         // not inherited
                    {
                        attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true);
                        if (attribs != null && attribs.Length > 0)
                        {
                            AddArgumentProcessor(mi);
                        }
                    }
                }
            }

            if (argumentProcessor == null)             // try to find an inherited one
            {
                foreach (MemberInfo mi in optionsType.GetMembers())
                {
                    if (mi.DeclaringType != mi.ReflectedType)                       // inherited
                    {
                        object[] attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true);
                        if (attribs != null && attribs.Length > 0)
                        {
                            AddArgumentProcessor(mi);
                        }
                    }
                }
            }
        }
示例#5
0
        public Options(string[] args, 
					   OptionsParsingMode parsingMode, 
					   bool breakSingleDashManyLettersIntoManyOptions, 
					   bool endOptionProcessingWithDoubleDash,
					   bool dontSplitOnCommas,
					   ErrorReporter reportError)
        {
            ParsingMode = parsingMode;
            BreakSingleDashManyLettersIntoManyOptions = breakSingleDashManyLettersIntoManyOptions;
            EndOptionProcessingWithDoubleDash = endOptionProcessingWithDoubleDash;
            DontSplitOnCommas = dontSplitOnCommas;
            if (reportError == null)
                ReportError = new ErrorReporter(DefaultErrorReporter);
            else
                ReportError = reportError;
            InitializeOtherDefaults();
            if (args != null)
                ProcessArgs(args);
        }
示例#6
0
		public OptionList(Options optionBundle)
		{
			if (optionBundle == null)
				throw new ArgumentNullException("optionBundle");

			Type optionsType = optionBundle.GetType();
			this.optionBundle = optionBundle;
			parsingMode = optionBundle.ParsingMode;
			breakSingleDashManyLettersIntoManyOptions = optionBundle.BreakSingleDashManyLettersIntoManyOptions;
			endOptionProcessingWithDoubleDash = optionBundle.EndOptionProcessingWithDoubleDash;
			ReportError = optionBundle.ReportError;

			ExtractEntryAssemblyInfo(optionsType);

			foreach(MemberInfo mi in optionsType.GetMembers())
			{
				object[] attribs = mi.GetCustomAttributes(typeof(KillOptionAttribute), true);
				if (attribs == null || attribs.Length == 0)
				{
					attribs = mi.GetCustomAttributes(typeof(OptionAttribute), true);
					if (attribs != null && attribs.Length > 0)
					{
						OptionDetails option = new OptionDetails(mi, (OptionAttribute) attribs[0], optionBundle);
						list.Add(option);
						HasSecondLevelHelp = HasSecondLevelHelp || option.SecondLevelHelp;
					}
					else if (mi.DeclaringType == mi.ReflectedType)
					{
						// not inherited
						attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true);
						if (attribs != null && attribs.Length > 0)
							AddArgumentProcessor(mi);
					}
				}
			}

			if (argumentProcessor == null) // try to find an inherited one
				foreach(MemberInfo mi in optionsType.GetMembers())
					if (mi.DeclaringType != mi.ReflectedType)
					{
						// inherited
						object[] attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true);
						if (attribs != null && attribs.Length > 0)
							AddArgumentProcessor(mi);
					}
		}
示例#7
0
        public OptionDetails(
            MemberInfo memberInfo,
            OptionAttribute option,
            object optionBundle,
            OptionsParsingMode parsingMode,
            bool dontSplitOnCommas
            )
        {
            ShortForm         = option.ShortForm;
            ParsingMode       = parsingMode;
            DontSplitOnCommas = dontSplitOnCommas;
            if (string.IsNullOrWhiteSpace(option.Name))
            {
                LongForm = (ShortForm == default(char)) ? memberInfo.Name : string.Empty;
            }
            else
            {
                LongForm = option.Name;
            }
            AlternateForm    = option.AlternateForm;
            ShortDescription = ExtractParamName(option.TranslatedDescription);
            Occurs           = 0;
            OptionBundle     = optionBundle;
            BooleanOption    = false;
            MemberInfo       = memberInfo;
            NeedsParameter   = false;
            Values           = null;
            MaxOccurs        = 1;
            VBCStyleBoolean  = option.VBCStyleBoolean;
            SecondLevelHelp  = option.SecondLevelHelp;
            Hidden           = false; // TODO: check other attributes

            ParameterType = TypeOfMember(memberInfo);
            var NonDefaultMessage = string.Format("MaxOccurs set to non default value ({0}) for a [{1}] option", option.MaxOccurs, MemberInfo);

            if (ParameterType != null)
            {
                if (ParameterType.FullName != "System.Boolean")
                {
                    if (LongForm.IndexOf(':') >= 0)
                    {
                        throw new InvalidOperationException(string.Format("Options with an embedded colon (':') in their visible name must be boolean!!! [{0} isn't]", MemberInfo));
                    }

                    NeedsParameter = true;

                    if (option.MaxOccurs != 1)
                    {
                        if (ParameterType.IsArray)
                        {
                            Values    = new ArrayList();
                            MaxOccurs = option.MaxOccurs;
                        }
                        else
                        {
                            if (MemberInfo is MethodInfo || MemberInfo is PropertyInfo)
                            {
                                MaxOccurs = option.MaxOccurs;
                            }
                            else
                            {
                                throw new InvalidOperationException(NonDefaultMessage);
                            }
                        }
                    }
                }
                else
                {
                    BooleanOption = true;
                    if (option.MaxOccurs != 1)
                    {
                        if (MemberInfo is MethodInfo || MemberInfo is PropertyInfo)
                        {
                            MaxOccurs = option.MaxOccurs;
                        }
                        else
                        {
                            throw new InvalidOperationException(NonDefaultMessage);
                        }
                    }
                }
            }
        }