7b0b9c7365
Solution + 23 src projects + 26 test projects renamed; folders, csproj, namespaces, and ScadaLinkDbContext/ScadaBridgeDbContext class updated. ActorSystem "scadalink" → "scadabridge", Akka seed-node URLs migrated. SQL roles/logins, LDAP domains, CLI command name, and CLI config dir (~/.scadalink → ~/.scadabridge) also renamed. Build green; 5 Host.Tests fail awaiting SQL login rename in next commit. Pre-existing StaleTagMonitor timing flakes unchanged. Rename script committed at tools/rename-to-scadabridge.sh.
120 lines
6.1 KiB
C#
120 lines
6.1 KiB
C#
using System.CommandLine;
|
|
using System.CommandLine.Parsing;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
public static class SharedScriptCommands
|
|
{
|
|
/// <summary>Builds the <c>shared-script</c> command group with list, get, create, update, and delete sub-commands.</summary>
|
|
/// <param name="urlOption">Shared management URL option.</param>
|
|
/// <param name="formatOption">Shared output format option.</param>
|
|
/// <param name="usernameOption">Shared username option.</param>
|
|
/// <param name="passwordOption">Shared password option.</param>
|
|
/// <returns>The configured <see cref="Command"/> for the shared-script group.</returns>
|
|
public static Command Build(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var command = new Command("shared-script") { Description = "Manage shared scripts" };
|
|
|
|
command.Add(BuildList(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildGet(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildCreate(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildUpdate(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildDelete(urlOption, formatOption, usernameOption, passwordOption));
|
|
|
|
return command;
|
|
}
|
|
|
|
private static Command BuildList(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var cmd = new Command("list") { Description = "List all shared scripts" };
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new ListSharedScriptsCommand());
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildGet(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Shared script ID", Required = true };
|
|
var cmd = new Command("get") { Description = "Get a shared script by ID" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new GetSharedScriptCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildCreate(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var nameOption = new Option<string>("--name") { Description = "Script name", Required = true };
|
|
var codeOption = new Option<string>("--code") { Description = "Script code", Required = true };
|
|
var parametersOption = new Option<string?>("--parameters") { Description = "Parameter definitions JSON" };
|
|
var returnDefOption = new Option<string?>("--return-def") { Description = "Return type definition" };
|
|
|
|
var cmd = new Command("create") { Description = "Create a shared script" };
|
|
cmd.Add(nameOption);
|
|
cmd.Add(codeOption);
|
|
cmd.Add(parametersOption);
|
|
cmd.Add(returnDefOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var name = result.GetValue(nameOption)!;
|
|
var code = result.GetValue(codeOption)!;
|
|
var parameters = result.GetValue(parametersOption);
|
|
var returnDef = result.GetValue(returnDefOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new CreateSharedScriptCommand(name, code, parameters, returnDef));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildUpdate(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Shared script ID", Required = true };
|
|
var nameOption = new Option<string>("--name") { Description = "Script name", Required = true };
|
|
var codeOption = new Option<string>("--code") { Description = "Script code", Required = true };
|
|
var parametersOption = new Option<string?>("--parameters") { Description = "Parameter definitions JSON" };
|
|
var returnDefOption = new Option<string?>("--return-def") { Description = "Return type definition" };
|
|
|
|
var cmd = new Command("update") { Description = "Update a shared script" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(nameOption);
|
|
cmd.Add(codeOption);
|
|
cmd.Add(parametersOption);
|
|
cmd.Add(returnDefOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
var name = result.GetValue(nameOption)!;
|
|
var code = result.GetValue(codeOption)!;
|
|
var parameters = result.GetValue(parametersOption);
|
|
var returnDef = result.GetValue(returnDefOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new UpdateSharedScriptCommand(id, name, code, parameters, returnDef));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildDelete(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Shared script ID", Required = true };
|
|
var cmd = new Command("delete") { Description = "Delete a shared script" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new DeleteSharedScriptCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
}
|