42 lines
1.8 KiB
C#
42 lines
1.8 KiB
C#
using System;
|
|
|
|
namespace XWorld.PublishTool
|
|
{
|
|
// PublishTool.Cli 的参数:--mode client|server --src <dir> --out <dir> --spec <json> [--key <pem>]
|
|
public sealed class CliOptions
|
|
{
|
|
public string Mode; // "client" | "server"
|
|
public string Src; // 构建产物目录
|
|
public string Out; // 落位目录(版本目录本体)
|
|
public string SpecPath; // resolved-spec.json
|
|
public string KeyPath; // 私钥 pem,可空=不签名
|
|
|
|
public const string Usage =
|
|
"用法: PublishTool.Cli --mode client|server --src <dir> --out <dir> --spec <resolved-spec.json> [--key <private.pem>]";
|
|
|
|
public static CliOptions Parse(string[] args)
|
|
{
|
|
var o = new CliOptions();
|
|
for (int i = 0; i < args.Length; i += 2)
|
|
{
|
|
if (i + 1 >= args.Length) throw new ArgumentException($"缺少 {args[i]} 的值\n{Usage}");
|
|
string v = args[i + 1];
|
|
switch (args[i])
|
|
{
|
|
case "--mode": o.Mode = v; break;
|
|
case "--src": o.Src = v; break;
|
|
case "--out": o.Out = v; break;
|
|
case "--spec": o.SpecPath = v; break;
|
|
case "--key": o.KeyPath = v; break;
|
|
default: throw new ArgumentException($"未知参数 {args[i]}\n{Usage}");
|
|
}
|
|
}
|
|
if (o.Mode != "client" && o.Mode != "server")
|
|
throw new ArgumentException($"--mode 必须是 client 或 server\n{Usage}");
|
|
if (string.IsNullOrEmpty(o.Src) || string.IsNullOrEmpty(o.Out) || string.IsNullOrEmpty(o.SpecPath))
|
|
throw new ArgumentException($"--src/--out/--spec 均必填\n{Usage}");
|
|
return o;
|
|
}
|
|
}
|
|
}
|