Throw exception when an option has multiple values but the target type is not an array

This commit is contained in:
Alexey Golub
2019-06-09 22:14:01 +03:00
parent 63d798977d
commit 1543076bf4

View File

@@ -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}].");
}
}
}
}