using System.CommandLine;
using System.CommandLine.Parsing;
namespace MfGames.ToolBuilder
{
///
/// Helper methods for pulling out values without performing the full parse.
///
public static class GlobalOptionHelper
{
public static TType GetArgumentValue(
Option option,
string[] arguments,
TType defaultValue)
{
var rootCommand = new RootCommand
{
option,
};
rootCommand.TreatUnmatchedTokensAsErrors = false;
ParseResult results = rootCommand.Parse(arguments);
if (!results.HasOption(option))
{
return defaultValue;
}
TType value = results.ValueForOption(option)!;
return value;
}
}
}