Skip to content

Commit bc732f1

Browse files
committed
Minor internal refactoring.
1 parent 41059ea commit bc732f1

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

src/libcmdline/Extensions/StringExtensions.cs

-5
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,5 @@ public static bool IsLongOption(this string value)
7878
{
7979
return value[0] == '-' && value[1] == '-';
8080
}
81-
82-
public static StringComparison GetStringComparison(this IParserSettings settings)
83-
{
84-
return settings.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
85-
}
8681
}
8782
}

src/libcmdline/Parser.cs

+27-19
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@
2121
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
// THE SOFTWARE.
2323
#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;
3434
using CommandLine.Text;
3535
#endregion
3636

3737
namespace CommandLine
38-
{
38+
{
39+
using System.IO;
40+
3941
/// <summary>
4042
/// Provides methods to parse command line arguments. Default implementation for <see cref="CommandLine.IParser"/>.
4143
/// </summary>
@@ -288,6 +290,11 @@ private static void SetParserStateIfNeeded(object options, IEnumerable<ParsingEr
288290
{
289291
parserState.Errors.Add(error);
290292
}
293+
}
294+
295+
private static StringComparison GetStringComparison(IParserSettings settings)
296+
{
297+
return settings.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
291298
}
292299

293300
private bool DoParseArguments(string[] args, object options)
@@ -442,11 +449,11 @@ private bool TryParseHelpVerb(string[] args, object options, Pair<MethodInfo, He
442449
{
443450
var helpWriter = Settings.HelpWriter;
444451
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)
447454
{
448-
// User explicitly requested help
449-
var verb = args.Length > 1 ? args[1] : null;
455+
// User explicitly requested help
456+
var verb = args.FirstOrDefault();
450457
if (verb != null)
451458
{
452459
var verbOption = optionMap[verb];
@@ -496,10 +503,11 @@ private void InvokeAutoBuildIfNeeded(object options)
496503
}
497504

498505
// 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()));
503511
}
504512

505513
private void Dispose(bool disposing)

0 commit comments

Comments
 (0)