Files
josh adams 98aadf5c36 - Categorized Turnkey commands
- Added ability to have input list options be headers (prefix with ;)
#rb nuno.leiria

#ROBOMERGE-SOURCE: CL 15472185 in //UE5/Release-5.0-EarlyAccess/...
#ROBOMERGE-BOT: STARSHIP (Release-5.0-EarlyAccess -> Main) (v771-15082668)

[CL 15472224 by josh adams in ue5-main branch]
2021-02-19 11:59:55 -04:00

64 lines
1.6 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using AutomationTool;
using UnrealBuildTool;
using System.Linq;
using Gauntlet;
namespace Turnkey.Commands
{
class Control : TurnkeyCommand
{
protected override CommandGroup Group => CommandGroup.Misc;
private delegate void PerformOperation(ITargetDevice Device);
protected override void Execute(string[] CommandOptions)
{
List<DeviceInfo> Devices = TurnkeyUtils.GetDevicesFromCommandLineOrUser(CommandOptions, null);
if (Devices == null)
{
return;
}
Dictionary<string, PerformOperation> Ops = new Dictionary<string, PerformOperation>();
Ops.Add("Connect", x => x.Connect());
Ops.Add("Disconnect", x => x.Disconnect());
Ops.Add("PowerOn", x => x.PowerOn());
Ops.Add("PowerOff", x => x.PowerOff());
Ops.Add("Reboot", x => x.Reboot());
bool bWasScripted = false;
// break if the GetGenericOption was scripted, otherwise we would loop forever
while (!bWasScripted)
{
string Operation = TurnkeyUtils.GetGenericOption(CommandOptions, Ops.Keys.ToList(), "Operation", out bWasScripted);
if (Operation == null)
{
return;
}
foreach (DeviceInfo Device in Devices)
{
TurnkeyUtils.Log($"Performing {Operation} on {Device.Platform}@{Device.Name}:");
try
{
ITargetDevice GauntletDevice = TurnkeyGauntletUtils.GetGauntletDevice(Device);
if (GauntletDevice != null)
{
Ops[Operation](GauntletDevice);
}
}
catch (Exception Ex)
{
TurnkeyUtils.Log($"Operation {Operation} failed : {Ex.Message}\n");
}
}
}
}
}
}