2222// POSSIBILITY OF SUCH DAMAGE.
2323#endregion
2424
25+ using System ;
2526using System . Collections . Generic ;
2627using System . Linq ;
28+ using Fclp . Internals . Extensions ;
2729
2830namespace Fclp . Internals . Parsing
2931{
@@ -32,8 +34,9 @@ namespace Fclp.Internals.Parsing
3234 /// </summary>
3335 public class CommandLineParserEngineMark2 : ICommandLineParserEngine
3436 {
35- private readonly List < string > _additionalOptionsFound = new List < string > ( ) ;
37+ private readonly List < string > _additionalArgumentsFound = new List < string > ( ) ;
3638 private readonly List < ParsedOption > _parsedOptions = new List < ParsedOption > ( ) ;
39+ private readonly OptionArgumentParser _optionArgumentParser = new OptionArgumentParser ( ) ;
3740
3841 /// <summary>
3942 /// Parses the specified <see><cref>T:System.String[]</cref></see> into appropriate <see cref="ParsedOption"/> objects..
@@ -52,7 +55,7 @@ public ParserEngineResult Parse(string[] args)
5255 ParseGroupIntoOption ( rawKey , optionGroup . Skip ( 1 ) ) ;
5356 }
5457
55- return new ParserEngineResult ( _parsedOptions , _additionalOptionsFound ) ;
58+ return new ParserEngineResult ( _parsedOptions , _additionalArgumentsFound ) ;
5659 }
5760
5861 private void ParseGroupIntoOption ( string rawKey , IEnumerable < string > optionGroup )
@@ -63,14 +66,14 @@ private void ParseGroupIntoOption(string rawKey, IEnumerable<string> optionGroup
6366
6467 TrimSuffix ( parsedOption ) ;
6568
66- new OptionArgumentParser ( ) . ParseArguments ( optionGroup , parsedOption ) ;
69+ _optionArgumentParser . ParseArguments ( optionGroup , parsedOption ) ;
6770
6871 AddParsedOptionToList ( parsedOption ) ;
6972 }
7073 else
7174 {
72- _additionalOptionsFound . Add ( rawKey ) ;
73- _additionalOptionsFound . AddRange ( optionGroup ) ;
75+ AddAdditionArgument ( rawKey ) ;
76+ optionGroup . ForEach ( AddAdditionArgument ) ;
7477 }
7578 }
7679
@@ -86,6 +89,14 @@ private void AddParsedOptionToList(ParsedOption parsedOption)
8689 }
8790 }
8891
92+ private void AddAdditionArgument ( string argument )
93+ {
94+ if ( IsEndOfOptionsKey ( argument ) == false )
95+ {
96+ _additionalArgumentsFound . Add ( argument ) ;
97+ }
98+ }
99+
89100 private static bool ShortOptionNeedsToBeSplit ( ParsedOption parsedOption )
90101 {
91102 return PrefixIsShortOption ( parsedOption . Prefix ) && parsedOption . Key . Length > 1 ;
@@ -122,12 +133,20 @@ private static void TrimSuffix(ParsedOption parsedOption)
122133 /// <param name="arg">The <see cref="System.String"/> to examine.</param>
123134 /// <returns><c>true</c> if <paramref name="arg"/> is a Option key; otherwise <c>false</c>.</returns>
124135 static bool IsAKey ( string arg )
125- {
136+ { // TODO: push related special char operations into there own object
126137 return arg != null
127138 && SpecialCharacters . OptionPrefix . Any ( arg . StartsWith )
128139 && SpecialCharacters . OptionPrefix . Any ( arg . Equals ) == false ;
129140 }
130141
142+ /// <summary>
143+ /// Determines whether the specified string indicates the end of parsed options.
144+ /// </summary>
145+ static bool IsEndOfOptionsKey ( string arg )
146+ {
147+ return string . Equals ( arg , SpecialCharacters . EndOfOptionsKey , StringComparison . InvariantCultureIgnoreCase ) ;
148+ }
149+
131150 /// <summary>
132151 /// Parses the specified <see><cref>T:System.String[]</cref></see> into key value pairs.
133152 /// </summary>
0 commit comments