Skip to content

Commit

Permalink
update CommandLineParser
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihanLi committed Jun 5, 2024
1 parent 9b6dc4e commit cc79fea
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/WeihanLi.Common/Helpers/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Diagnostics.CodeAnalysis;
using System.Text;
using WeihanLi.Extensions;

namespace WeihanLi.Common.Helpers;

Expand Down Expand Up @@ -97,12 +96,26 @@ public static IEnumerable<string> ParseLine(string line, LineParseOptions? optio
/// <param name="defaultValue">default argument value when not found</param>
/// <returns>argument value</returns>
[return: NotNullIfNotNull(nameof(defaultValue))]
[Obsolete("Please use Value instead")]
public static string? ArgValue(string[] args, string argumentName, string? defaultValue = default)
{
return GetArgumentValueInternal(args, argumentName) ?? defaultValue;
return GetOptionValueInternal(args, argumentName) ?? defaultValue;
}

private static string? GetArgumentValueInternal(string[] args, string argumentName)
/// <summary>
/// Get argument value from arguments
/// </summary>
/// <param name="optionName">argument name to get value</param>
/// <param name="defaultValue">default argument value when not found</param>
/// <param name="args">arguments</param>
/// <returns>argument value</returns>
[return: NotNullIfNotNull(nameof(defaultValue))]
public static string? Value(string optionName, string? defaultValue = default, string[]? args = null)
{
return GetOptionValueInternal(args ?? Environment.GetCommandLineArgs(), optionName) ?? defaultValue;
}

private static string? GetOptionValueInternal(string[] args, string argumentName)
{
for (var i = 0; i < args.Length; i++)
{
Expand Down

0 comments on commit cc79fea

Please sign in to comment.