refactor(commons): consolidate List element-type/coercion into AttributeValueCodec; InstanceActor + CLI reuse it (#93)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Parsing;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
||||
|
||||
@@ -239,9 +241,16 @@ public static class TemplateCommands
|
||||
internal const string ElementTypeOptionDescription =
|
||||
"Element scalar type for a List attribute (String, Int32, Float, Double, Boolean, DateTime). Required when --data-type is List.";
|
||||
|
||||
/// <summary>The element scalar types permitted for a List attribute (matches the Management API).</summary>
|
||||
/// <summary>
|
||||
/// The element scalar types permitted for a List attribute — derived from the
|
||||
/// single source of truth, <see cref="AttributeValueCodec.IsValidElementType"/>,
|
||||
/// so the CLI never drifts from the codec/Management API.
|
||||
/// </summary>
|
||||
private static readonly string[] ValidElementScalars =
|
||||
{ "String", "Int32", "Float", "Double", "Boolean", "DateTime" };
|
||||
Enum.GetValues<DataType>()
|
||||
.Where(AttributeValueCodec.IsValidElementType)
|
||||
.Select(t => t.ToString())
|
||||
.ToArray();
|
||||
|
||||
/// <summary>
|
||||
/// Validates the <c>--data-type</c> / <c>--element-type</c> combination client-side so
|
||||
@@ -268,7 +277,8 @@ public static class TemplateCommands
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ValidElementScalars.Contains(elementType!.Trim(), StringComparer.OrdinalIgnoreCase))
|
||||
if (!Enum.TryParse<DataType>(elementType!.Trim(), ignoreCase: true, out var parsed)
|
||||
|| !AttributeValueCodec.IsValidElementType(parsed))
|
||||
{
|
||||
error = $"Invalid --element-type '{elementType}'. Valid List element scalars are: "
|
||||
+ string.Join(", ", ValidElementScalars) + ".";
|
||||
|
||||
Reference in New Issue
Block a user