|
21 | 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 22 | // THE SOFTWARE.
|
23 | 23 | #endregion
|
24 |
| -#region Using Directives |
25 |
| -using System; |
26 |
| -using System.Collections.Generic; |
27 |
| -using System.Diagnostics.CodeAnalysis; |
28 |
| -using System.Globalization; |
29 |
| -using System.Reflection; |
30 |
| -using System.Linq; |
31 |
| -using CommandLine.Extensions; |
32 |
| -using CommandLine.Helpers; |
33 |
| -using CommandLine.Infrastructure; |
| 24 | +#region Using Directives |
| 25 | +using System; |
| 26 | +using System.Collections.Generic; |
| 27 | +using System.Diagnostics.CodeAnalysis; |
| 28 | +using System.Globalization; |
| 29 | +using System.Linq; |
| 30 | +using System.Reflection; |
| 31 | +using CommandLine.Extensions; |
| 32 | +using CommandLine.Helpers; |
| 33 | +using CommandLine.Infrastructure; |
34 | 34 | using CommandLine.Text;
|
35 | 35 | #endregion
|
36 | 36 |
|
37 | 37 | namespace CommandLine
|
38 |
| -{ |
| 38 | +{ |
| 39 | + using System.IO; |
| 40 | + |
39 | 41 | /// <summary>
|
40 | 42 | /// Provides methods to parse command line arguments. Default implementation for <see cref="CommandLine.IParser"/>.
|
41 | 43 | /// </summary>
|
@@ -288,6 +290,11 @@ private static void SetParserStateIfNeeded(object options, IEnumerable<ParsingEr
|
288 | 290 | {
|
289 | 291 | parserState.Errors.Add(error);
|
290 | 292 | }
|
| 293 | + } |
| 294 | + |
| 295 | + private static StringComparison GetStringComparison(IParserSettings settings) |
| 296 | + { |
| 297 | + return settings.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; |
291 | 298 | }
|
292 | 299 |
|
293 | 300 | private bool DoParseArguments(string[] args, object options)
|
@@ -442,11 +449,11 @@ private bool TryParseHelpVerb(string[] args, object options, Pair<MethodInfo, He
|
442 | 449 | {
|
443 | 450 | var helpWriter = Settings.HelpWriter;
|
444 | 451 | if (helpInfo != null && helpWriter != null)
|
445 |
| - { |
446 |
| - if (string.Compare(args[0], helpInfo.Right.LongName, Settings.GetStringComparison()) == 0) |
| 452 | + { |
| 453 | + if (string.Compare(args[0], helpInfo.Right.LongName, GetStringComparison(Settings)) == 0) |
447 | 454 | {
|
448 |
| - // User explicitly requested help |
449 |
| - var verb = args.Length > 1 ? args[1] : null; |
| 455 | + // User explicitly requested help |
| 456 | + var verb = args.FirstOrDefault(); |
450 | 457 | if (verb != null)
|
451 | 458 | {
|
452 | 459 | var verbOption = optionMap[verb];
|
@@ -496,10 +503,11 @@ private void InvokeAutoBuildIfNeeded(object options)
|
496 | 503 | }
|
497 | 504 |
|
498 | 505 | // We print help text for the user
|
499 |
| - Settings.HelpWriter.Write(HelpText.AutoBuild( |
500 |
| - options, |
501 |
| - current => HelpText.DefaultParsingErrorsHandler(options, current), |
502 |
| - options.HasVerbs())); |
| 506 | + Settings.HelpWriter.Write( |
| 507 | + HelpText.AutoBuild( |
| 508 | + options, |
| 509 | + current => HelpText.DefaultParsingErrorsHandler(options, current), |
| 510 | + options.HasVerbs())); |
503 | 511 | }
|
504 | 512 |
|
505 | 513 | private void Dispose(bool disposing)
|
|
0 commit comments