mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Throw exception when an option has multiple values but the target type is not an array
This commit is contained in:
@@ -228,13 +228,19 @@ namespace CliFx.Services
|
||||
throw new CommandOptionConvertException(
|
||||
$"Can't convert sequence of values [{option.Values.JoinToString(", ")}] to type [{targetType}].");
|
||||
}
|
||||
else
|
||||
else if (option.Values.Count <= 1)
|
||||
{
|
||||
// Take first value and ignore the rest
|
||||
var value = option.Values.FirstOrDefault();
|
||||
var value = option.Values.SingleOrDefault();
|
||||
|
||||
return ConvertValue(value, targetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: better exception
|
||||
throw new CommandOptionConvertException(
|
||||
$"Can't convert sequence of values [{option.Values.JoinToString(", ")}] to type [{targetType}].");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user