예제 #1
0
 public ParamsObject(string[] args)
 {
     try
     {
         this.args             = args;
         _defaultSwitchOptions = new SwitchOptions(new List <char> {
             '/'
         }, new List <char> {
             ':'
         }, "[_A-Za-z]+[_A-Za-z0-9]*");
         _defaultTypeParser     = new PrimitiveParser();
         _defaultSwitchParser   = new SwitchParser(TypeParser, this);
         _helpOptions           = new HelpTextOptions(HelpTextLength, HelpTextIndentLength, HelpCommands);
         _defaultHelpTextParser = new BasicHelpTextParser(_helpOptions, TypeParser);
         if (GetHelpIfNeeded() == string.Empty)
         {
             SwitchParser.ParseSwitches(args);
         }
         _paramExceptionDictionary = new Dictionary <Func <bool>, string>();
         AddAdditionalParamChecks();
         foreach (var item in GetParamExceptionDictionary())
         {
             _paramExceptionDictionary.Add(item.Key, item.Value);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #2
0
 private void Initialize()
 {
     _defaultSwitchOptions = new SwitchOptions(new List <char> {
         '/'
     }, new List <char> {
         ':'
     }, "[_A-Za-z]+[_A-Za-z0-9]*");
     _defaultTypeParserContainer = new DefaultTypeContainer();
     _defaultSwitchParser        = new SwitchParser(TypeParser, this);
     _helpOptions           = new HelpTextOptions(HelpTextLength, HelpTextIndentLength, HelpCommands);
     _defaultHelpTextParser = new BasicHelpTextParser(_helpOptions, TypeParser);
     _defaultArgMaker       = new DefaultArgumentCreator();
 }
예제 #3
0
 public string[] GetArgs(string args, SwitchOptions _options, IHelpTextParser HelpTextParser)
 {
     //check for help
     //if not needed, parse args
     string[] _checkForHelp = args.Split(' ');
     if (_checkForHelp.Length > 0 && !string.IsNullOrWhiteSpace(HelpTextParser.GetHelpIfNeeded(_checkForHelp, new BlankParamsObject())))
     {
         return(_checkForHelp);
     }
     else
     {
         return(GetArgs(args, _options));
     }
 }
예제 #4
0
        public string[] GetArgs(string args, SwitchOptions _options)
        {
            //Two types of args:
            //1) no switch (using default ordinal)
            //2) has switch-value pair

            List <string> _matchArgs = new List <string>();

            string _newFlagRegex = _options.FlagSwitchRegex;

            if (_newFlagRegex.EndsWith("\\z"))
            {
                _newFlagRegex = _newFlagRegex.Substring(0, _newFlagRegex.Length - 2);
            }

            string _switchOrFlagRegex = $"({_options.SwitchRegex}|{_newFlagRegex})";
            Match  _match             = Regex.Match(args, _switchOrFlagRegex);
            //_match = Regex.Match(args, $"({_options.FlagSwitchRegex})");
            int   _lastStartIndex = 0;
            int   _lastEndIndex   = 0;
            Match _lastMatch      = _match;

            while (_match.Success)
            {
                _match = _match.NextMatch();
                if (_match.Success)
                {
                    _lastEndIndex = _match.Index;
                    _matchArgs.Add(args.Substring(_lastStartIndex, _lastEndIndex - _lastStartIndex).Trim());
                    _lastStartIndex = _lastEndIndex;
                    _lastMatch      = _match;
                }
                else
                {
                    _matchArgs.Add(args.Substring(_lastStartIndex, args.Length - _lastStartIndex).Trim());
                }
            }
            return(_matchArgs.ToArray());
        }
예제 #5
0
 private void GetSwitchOptions()
 {
     _options = new SwitchOptions(_paramsObject.Options.SwitchStartChars, _paramsObject.Options.SwitchEndChars, _paramsObject.Options.SwitchNameRegex);
 }
예제 #6
0
 protected virtual void GetSwitchOptions()
 {
     _options = new SwitchOptions(_paramsObject.Options.SwitchStartChars, _paramsObject.Options.SwitchEndChars, _paramsObject.Options.SwitchNameRegex);
 }