feat: implement all CLI command groups (10 groups, 11 files)
This commit is contained in:
81
src/ScadaLink.CLI/Commands/SiteCommands.cs
Normal file
81
src/ScadaLink.CLI/Commands/SiteCommands.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Parsing;
|
||||
using ScadaLink.Commons.Messages.Management;
|
||||
|
||||
namespace ScadaLink.CLI.Commands;
|
||||
|
||||
public static class SiteCommands
|
||||
{
|
||||
public static Command Build(Option<string> contactPointsOption, Option<string> formatOption)
|
||||
{
|
||||
var command = new Command("site") { Description = "Manage sites" };
|
||||
|
||||
command.Add(BuildList(contactPointsOption, formatOption));
|
||||
command.Add(BuildCreate(contactPointsOption, formatOption));
|
||||
command.Add(BuildDelete(contactPointsOption, formatOption));
|
||||
command.Add(BuildDeployArtifacts(contactPointsOption, formatOption));
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
private static Command BuildList(Option<string> contactPointsOption, Option<string> formatOption)
|
||||
{
|
||||
var cmd = new Command("list") { Description = "List all sites" };
|
||||
cmd.SetAction(async (ParseResult result) =>
|
||||
{
|
||||
return await CommandHelpers.ExecuteCommandAsync(
|
||||
result, contactPointsOption, formatOption, new ListSitesCommand());
|
||||
});
|
||||
return cmd;
|
||||
}
|
||||
|
||||
private static Command BuildCreate(Option<string> contactPointsOption, Option<string> formatOption)
|
||||
{
|
||||
var nameOption = new Option<string>("--name") { Description = "Site name", Required = true };
|
||||
var identifierOption = new Option<string>("--identifier") { Description = "Site identifier", Required = true };
|
||||
var descOption = new Option<string?>("--description") { Description = "Site description" };
|
||||
|
||||
var cmd = new Command("create") { Description = "Create a new site" };
|
||||
cmd.Add(nameOption);
|
||||
cmd.Add(identifierOption);
|
||||
cmd.Add(descOption);
|
||||
cmd.SetAction(async (ParseResult result) =>
|
||||
{
|
||||
var name = result.GetValue(nameOption)!;
|
||||
var identifier = result.GetValue(identifierOption)!;
|
||||
var desc = result.GetValue(descOption);
|
||||
return await CommandHelpers.ExecuteCommandAsync(
|
||||
result, contactPointsOption, formatOption,
|
||||
new CreateSiteCommand(name, identifier, desc));
|
||||
});
|
||||
return cmd;
|
||||
}
|
||||
|
||||
private static Command BuildDelete(Option<string> contactPointsOption, Option<string> formatOption)
|
||||
{
|
||||
var idOption = new Option<int>("--id") { Description = "Site ID", Required = true };
|
||||
var cmd = new Command("delete") { Description = "Delete a site" };
|
||||
cmd.Add(idOption);
|
||||
cmd.SetAction(async (ParseResult result) =>
|
||||
{
|
||||
var id = result.GetValue(idOption);
|
||||
return await CommandHelpers.ExecuteCommandAsync(
|
||||
result, contactPointsOption, formatOption, new DeleteSiteCommand(id));
|
||||
});
|
||||
return cmd;
|
||||
}
|
||||
|
||||
private static Command BuildDeployArtifacts(Option<string> contactPointsOption, Option<string> formatOption)
|
||||
{
|
||||
var siteIdOption = new Option<int?>("--site-id") { Description = "Target site ID (all sites if omitted)" };
|
||||
var cmd = new Command("deploy-artifacts") { Description = "Deploy artifacts to site(s)" };
|
||||
cmd.Add(siteIdOption);
|
||||
cmd.SetAction(async (ParseResult result) =>
|
||||
{
|
||||
var siteId = result.GetValue(siteIdOption);
|
||||
return await CommandHelpers.ExecuteCommandAsync(
|
||||
result, contactPointsOption, formatOption, new MgmtDeployArtifactsCommand(siteId));
|
||||
});
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user