This commit is contained in:
Tyrrrz
2024-05-31 18:49:20 +03:00
parent cad1c14474
commit 24fd87b1e1
3 changed files with 15 additions and 6 deletions

View File

@@ -21,8 +21,7 @@ internal class CommandBinder(ITypeActivator typeActivator)
// Custom converter
if (inputSchema.Converter is not null)
{
var converter = typeActivator.CreateInstance<IBindingConverter>(inputSchema.Converter);
return converter.Convert(rawValue);
return inputSchema.Converter.Convert(rawValue);
}
// Assignable from a string (e.g. string itself, object, etc)
@@ -336,7 +335,7 @@ internal class CommandBinder(ITypeActivator typeActivator)
// Environment variable
else if (environmentVariableInput is not null)
{
var rawValues = optionSchema.Property.IsScalar()
var rawValues = optionSchema.IsScalar
? [environmentVariableInput.Value]
: environmentVariableInput.SplitValues();

View File

@@ -10,6 +10,8 @@ namespace CliFx.Schema;
/// </summary>
public class OptionSchema(
PropertyDescriptor property,
bool isScalar,
IReadOnlyList<object?>? validValues,
string? name,
char? shortName,
string? environmentVariable,
@@ -23,10 +25,10 @@ public class OptionSchema(
public PropertyDescriptor Property { get; } = property;
/// <inheritdoc />
public bool IsScalar { get; }
public bool IsScalar { get; } = isScalar;
/// <inheritdoc />
public IReadOnlyList<object?>? ValidValues { get; }
public IReadOnlyList<object?>? ValidValues { get; } = validValues;
/// <summary>
/// Option name.

View File

@@ -8,6 +8,8 @@ namespace CliFx.Schema;
/// </summary>
public class ParameterSchema(
PropertyDescriptor property,
bool isScalar,
IReadOnlyList<object?>? validValues,
int order,
string name,
bool isRequired,
@@ -19,6 +21,12 @@ public class ParameterSchema(
/// <inheritdoc />
public PropertyDescriptor Property { get; } = property;
/// <inheritdoc />
public bool IsScalar { get; } = isScalar;
/// <inheritdoc />
public IReadOnlyList<object?>? ValidValues { get; } = validValues;
/// <summary>
/// Order, in which the parameter is bound from the command-line arguments.
/// </summary>
@@ -46,5 +54,5 @@ public class ParameterSchema(
public IReadOnlyList<IBindingValidator> Validators { get; } = validators;
internal string GetFormattedIdentifier() =>
!Property.IsEnumerable ? $"<{Name}>" : $"<{Name}...>";
IsScalar ? $"<{Name}>" : $"<{Name}...>";
}