22
22
// POSSIBILITY OF SUCH DAMAGE.
23
23
#endregion
24
24
25
+ using System ;
25
26
using System . Collections . Generic ;
26
27
using System . Linq ;
28
+ using Fclp . Internals . Extensions ;
27
29
28
30
namespace Fclp . Internals . Parsing
29
31
{
@@ -32,8 +34,9 @@ namespace Fclp.Internals.Parsing
32
34
/// </summary>
33
35
public class CommandLineParserEngineMark2 : ICommandLineParserEngine
34
36
{
35
- private readonly List < string > _additionalOptionsFound = new List < string > ( ) ;
37
+ private readonly List < string > _additionalArgumentsFound = new List < string > ( ) ;
36
38
private readonly List < ParsedOption > _parsedOptions = new List < ParsedOption > ( ) ;
39
+ private readonly OptionArgumentParser _optionArgumentParser = new OptionArgumentParser ( ) ;
37
40
38
41
/// <summary>
39
42
/// 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)
52
55
ParseGroupIntoOption ( rawKey , optionGroup . Skip ( 1 ) ) ;
53
56
}
54
57
55
- return new ParserEngineResult ( _parsedOptions , _additionalOptionsFound ) ;
58
+ return new ParserEngineResult ( _parsedOptions , _additionalArgumentsFound ) ;
56
59
}
57
60
58
61
private void ParseGroupIntoOption ( string rawKey , IEnumerable < string > optionGroup )
@@ -63,14 +66,14 @@ private void ParseGroupIntoOption(string rawKey, IEnumerable<string> optionGroup
63
66
64
67
TrimSuffix ( parsedOption ) ;
65
68
66
- new OptionArgumentParser ( ) . ParseArguments ( optionGroup , parsedOption ) ;
69
+ _optionArgumentParser . ParseArguments ( optionGroup , parsedOption ) ;
67
70
68
71
AddParsedOptionToList ( parsedOption ) ;
69
72
}
70
73
else
71
74
{
72
- _additionalOptionsFound . Add ( rawKey ) ;
73
- _additionalOptionsFound . AddRange ( optionGroup ) ;
75
+ AddAdditionArgument ( rawKey ) ;
76
+ optionGroup . ForEach ( AddAdditionArgument ) ;
74
77
}
75
78
}
76
79
@@ -86,6 +89,14 @@ private void AddParsedOptionToList(ParsedOption parsedOption)
86
89
}
87
90
}
88
91
92
+ private void AddAdditionArgument ( string argument )
93
+ {
94
+ if ( IsEndOfOptionsKey ( argument ) == false )
95
+ {
96
+ _additionalArgumentsFound . Add ( argument ) ;
97
+ }
98
+ }
99
+
89
100
private static bool ShortOptionNeedsToBeSplit ( ParsedOption parsedOption )
90
101
{
91
102
return PrefixIsShortOption ( parsedOption . Prefix ) && parsedOption . Key . Length > 1 ;
@@ -122,12 +133,20 @@ private static void TrimSuffix(ParsedOption parsedOption)
122
133
/// <param name="arg">The <see cref="System.String"/> to examine.</param>
123
134
/// <returns><c>true</c> if <paramref name="arg"/> is a Option key; otherwise <c>false</c>.</returns>
124
135
static bool IsAKey ( string arg )
125
- {
136
+ { // TODO: push related special char operations into there own object
126
137
return arg != null
127
138
&& SpecialCharacters . OptionPrefix . Any ( arg . StartsWith )
128
139
&& SpecialCharacters . OptionPrefix . Any ( arg . Equals ) == false ;
129
140
}
130
141
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
+
131
150
/// <summary>
132
151
/// Parses the specified <see><cref>T:System.String[]</cref></see> into key value pairs.
133
152
/// </summary>
0 commit comments