From 24fd87b1e1eea327de6a10ce569496ab153f2800 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Fri, 31 May 2024 18:49:20 +0300 Subject: [PATCH] asd --- CliFx/CommandBinder.cs | 5 ++--- CliFx/Schema/OptionSchema.cs | 6 ++++-- CliFx/Schema/ParameterSchema.cs | 10 +++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CliFx/CommandBinder.cs b/CliFx/CommandBinder.cs index a815626..56bc4ed 100644 --- a/CliFx/CommandBinder.cs +++ b/CliFx/CommandBinder.cs @@ -21,8 +21,7 @@ internal class CommandBinder(ITypeActivator typeActivator) // Custom converter if (inputSchema.Converter is not null) { - var converter = typeActivator.CreateInstance(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(); diff --git a/CliFx/Schema/OptionSchema.cs b/CliFx/Schema/OptionSchema.cs index 8638c8e..63cf1ff 100644 --- a/CliFx/Schema/OptionSchema.cs +++ b/CliFx/Schema/OptionSchema.cs @@ -10,6 +10,8 @@ namespace CliFx.Schema; /// public class OptionSchema( PropertyDescriptor property, + bool isScalar, + IReadOnlyList? validValues, string? name, char? shortName, string? environmentVariable, @@ -23,10 +25,10 @@ public class OptionSchema( public PropertyDescriptor Property { get; } = property; /// - public bool IsScalar { get; } + public bool IsScalar { get; } = isScalar; /// - public IReadOnlyList? ValidValues { get; } + public IReadOnlyList? ValidValues { get; } = validValues; /// /// Option name. diff --git a/CliFx/Schema/ParameterSchema.cs b/CliFx/Schema/ParameterSchema.cs index ce5dabe..2eb0819 100644 --- a/CliFx/Schema/ParameterSchema.cs +++ b/CliFx/Schema/ParameterSchema.cs @@ -8,6 +8,8 @@ namespace CliFx.Schema; /// public class ParameterSchema( PropertyDescriptor property, + bool isScalar, + IReadOnlyList? validValues, int order, string name, bool isRequired, @@ -19,6 +21,12 @@ public class ParameterSchema( /// public PropertyDescriptor Property { get; } = property; + /// + public bool IsScalar { get; } = isScalar; + + /// + public IReadOnlyList? ValidValues { get; } = validValues; + /// /// Order, in which the parameter is bound from the command-line arguments. /// @@ -46,5 +54,5 @@ public class ParameterSchema( public IReadOnlyList Validators { get; } = validators; internal string GetFormattedIdentifier() => - !Property.IsEnumerable ? $"<{Name}>" : $"<{Name}...>"; + IsScalar ? $"<{Name}>" : $"<{Name}...>"; }