diff --git a/src/WeihanLi.Common/Helpers/CommandLineParser.cs b/src/WeihanLi.Common/Helpers/CommandLineParser.cs index bcd58fde..81fc6c24 100644 --- a/src/WeihanLi.Common/Helpers/CommandLineParser.cs +++ b/src/WeihanLi.Common/Helpers/CommandLineParser.cs @@ -3,7 +3,6 @@ using System.Diagnostics.CodeAnalysis; using System.Text; -using WeihanLi.Extensions; namespace WeihanLi.Common.Helpers; @@ -97,12 +96,26 @@ public static IEnumerable ParseLine(string line, LineParseOptions? optio /// default argument value when not found /// argument value [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) + /// + /// Get argument value from arguments + /// + /// argument name to get value + /// default argument value when not found + /// arguments + /// argument value + [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++) {