397d3c5c4f
Rename across every client surface using each language's idiomatic convention:
* .NET clients/dotnet/MxGateway.Client[.Cli|.Tests]/
-> clients/dotnet/ZB.MOM.WW.MxGateway.Client[.Cli|.Tests]/
namespaces -> ZB.MOM.WW.MxGateway.Client[.Cli|.Tests]
contracts ProjectReference repointed to ZB.MOM.WW.MxGateway.Contracts
sln migrated to slnx (dotnet sln migrate)
* Python src/mxgateway -> src/zb_mom_ww_mxgateway
src/mxgateway_cli -> src/zb_mom_ww_mxgateway_cli
distribution: mxaccess-gateway-client -> zb-mom-ww-mxaccess-gateway-client
* Rust crate: mxgateway-client -> zb-mom-ww-mxgateway-client
build.rs proto path repointed
* Java subprojects: mxgateway-{client,cli} -> zb-mom-ww-mxgateway-{client,cli}
packages com.dohertylan.mxgateway -> com.zb.mom.ww.mxgateway
group com.dohertylan.mxgateway -> com.zb.mom.ww.mxgateway
rootProject mxaccessgw-java -> zb-mom-ww-mxaccessgw-java
* Go generate-proto.ps1 proto path repointed; module path and
package mxgateway kept (Go convention).
* proto-inputs.json: generatedOutputs.python updated to new package path.
* scripts/run-client-e2e-tests.ps1: Java CLI install path + gradle task
updated to zb-mom-ww-mxgateway-cli.
CLI binary names (mxgw, mxgw-py, mxgw-go, mxgateway-cli) and wire-level
identifiers (MXGATEWAY_* env vars, the mxgw_<id>_<secret> API key
prefix, protobuf package names like mxaccess_gateway.v1, all MXAccess
references) intentionally NOT renamed.
Fix pre-existing alarms-over-gateway breaks unblocked by the rename:
* mxaccess_gateway.proto: add missing public message QueryActiveAlarmsRequest
{session_id, client_correlation_id, alarm_filter_prefix} and missing
rpc QueryActiveAlarms(QueryActiveAlarmsRequest) returns
(stream ActiveAlarmSnapshot). All four typed clients referenced
these but they were absent from the proto.
* MxAccessGatewayService.QueryActiveAlarms: implement the new RPC on
the server, streaming from IGatewayAlarmService.CurrentAlarms with
optional alarm_filter_prefix filter.
* clients/dotnet/.../DiscoverHierarchyOptions.cs: add the hand-written
.NET POCO that wraps DiscoverHierarchyRequest (referenced by
GalaxyRepositoryClient.DiscoverHierarchyAsync but never authored).
* Drop retired session_id field references from
AcknowledgeAlarmRequest/AcknowledgeAlarmReply test fixtures across
.NET, Rust, Go, and Python clients.
* Rust integration test: add the missing stream_alarms impl on the
fake MxAccessGateway server (the trait gained the method, fake
didn't).
* Rust CLI test: bump expected gatewayProtocolVersion 2 -> 3.
Regenerated artifacts updated in this commit:
* src/ZB.MOM.WW.MxGateway.Contracts/Generated/{MxaccessGateway,MxaccessGatewayGrpc}.cs
* clients/python/src/zb_mom_ww_mxgateway/generated/*_pb2{,_grpc}.py
* clients/go/internal/generated/*.pb.go
(C# regenerated by Grpc.Tools on contracts build; Python and Go via
their generate-proto.ps1 scripts; Rust regenerates from .proto via
tonic-build at compile time so no checked-in artefact.)
Verification: 472 server tests, 275 worker tests (9 dev-rig skipped),
18 integration tests (live MxAccess + LDAP + Galaxy), 57 .NET client
tests, 32 Rust workspace tests, 39 Python tests, all Go packages, and
gradle build for Java all pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
139 lines
5.0 KiB
C#
139 lines
5.0 KiB
C#
using System.Globalization;
|
|
|
|
namespace ZB.MOM.WW.MxGateway.Client.Cli;
|
|
|
|
/// <summary>Parses command-line arguments into flags and named values.</summary>
|
|
internal sealed class CliArguments
|
|
{
|
|
private readonly Dictionary<string, string> _values = new(StringComparer.OrdinalIgnoreCase);
|
|
private readonly HashSet<string> _flags = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
/// <summary>Initializes a new instance by parsing the given command-line arguments.</summary>
|
|
/// <param name="args">Unparsed command-line arguments; flags prefixed with '--' and values follow their flag.</param>
|
|
public CliArguments(IEnumerable<string> args)
|
|
{
|
|
string? pendingName = null;
|
|
|
|
foreach (string arg in args)
|
|
{
|
|
if (arg.StartsWith("--", StringComparison.Ordinal))
|
|
{
|
|
if (pendingName is not null)
|
|
{
|
|
_flags.Add(pendingName);
|
|
}
|
|
|
|
pendingName = arg[2..];
|
|
continue;
|
|
}
|
|
|
|
if (pendingName is null)
|
|
{
|
|
throw new ArgumentException($"Unexpected argument '{arg}'.");
|
|
}
|
|
|
|
_values[pendingName] = arg;
|
|
pendingName = null;
|
|
}
|
|
|
|
if (pendingName is not null)
|
|
{
|
|
_flags.Add(pendingName);
|
|
}
|
|
}
|
|
|
|
/// <summary>Returns whether the named flag was present in the arguments.</summary>
|
|
/// <param name="name">The flag name (without '--' prefix).</param>
|
|
public bool HasFlag(string name)
|
|
{
|
|
return _flags.Contains(name);
|
|
}
|
|
|
|
/// <summary>Returns the value for a named argument, or <c>null</c> if absent.</summary>
|
|
/// <param name="name">The argument name (without '--' prefix).</param>
|
|
public string? GetOptional(string name)
|
|
{
|
|
return _values.TryGetValue(name, out string? value)
|
|
? value
|
|
: null;
|
|
}
|
|
|
|
/// <summary>Returns the value for a required named argument, or throws if absent.</summary>
|
|
/// <param name="name">The argument name (without '--' prefix).</param>
|
|
public string GetRequired(string name)
|
|
{
|
|
string? value = GetOptional(name);
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
throw new ArgumentException($"Missing required option --{name}.");
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
/// <summary>Parses and returns an int32 argument, or the default value if absent.</summary>
|
|
/// <param name="name">The argument name (without '--' prefix).</param>
|
|
/// <param name="defaultValue">The default value if the argument is absent; if <c>null</c>, the argument is required.</param>
|
|
public int GetInt32(string name, int? defaultValue = null)
|
|
{
|
|
string? value = GetOptional(name);
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
if (defaultValue.HasValue)
|
|
{
|
|
return defaultValue.Value;
|
|
}
|
|
|
|
throw new ArgumentException($"Missing required option --{name}.");
|
|
}
|
|
|
|
return int.Parse(value, CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
/// <summary>Parses and returns a uint32 argument, or the default value if absent.</summary>
|
|
/// <param name="name">The argument name (without '--' prefix).</param>
|
|
/// <param name="defaultValue">The default value if the argument is absent.</param>
|
|
public uint GetUInt32(string name, uint defaultValue)
|
|
{
|
|
string? value = GetOptional(name);
|
|
return string.IsNullOrWhiteSpace(value)
|
|
? defaultValue
|
|
: uint.Parse(value, CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
/// <summary>Parses and returns a uint64 argument, or the default value if absent.</summary>
|
|
/// <param name="name">The argument name (without '--' prefix).</param>
|
|
/// <param name="defaultValue">The default value if the argument is absent.</param>
|
|
public ulong GetUInt64(string name, ulong defaultValue)
|
|
{
|
|
string? value = GetOptional(name);
|
|
return string.IsNullOrWhiteSpace(value)
|
|
? defaultValue
|
|
: ulong.Parse(value, CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
/// <summary>Parses and returns a TimeSpan argument, or the default value if absent. Supports "ms", "s", and standard TimeSpan format.</summary>
|
|
/// <param name="name">The argument name (without '--' prefix).</param>
|
|
/// <param name="defaultValue">The default value if the argument is absent.</param>
|
|
public TimeSpan GetDuration(string name, TimeSpan defaultValue)
|
|
{
|
|
string? value = GetOptional(name);
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
return defaultValue;
|
|
}
|
|
|
|
if (value.EndsWith("ms", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return TimeSpan.FromMilliseconds(double.Parse(value[..^2], CultureInfo.InvariantCulture));
|
|
}
|
|
|
|
if (value.EndsWith('s'))
|
|
{
|
|
return TimeSpan.FromSeconds(double.Parse(value[..^1], CultureInfo.InvariantCulture));
|
|
}
|
|
|
|
return TimeSpan.Parse(value, CultureInfo.InvariantCulture);
|
|
}
|
|
}
|