LANCommander/LANCommander.SDK/PowerShell/Cmdlets/Disconnect-SteamCmd.cs

32 lines
1,016 B
C#

using System;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
using LANCommander.Steam.Abstractions;
using LANCommander.Steam.Enums;
namespace LANCommander.SDK.PowerShell.Cmdlets;
[Cmdlet(VerbsCommunications.Disconnect, "SteamCmd")]
[OutputType(typeof(SteamCmdStatus))]
public class DisconnectSteamCmdCmdlet : AsyncCmdlet
{
[Parameter(Mandatory = true, Position = 0, HelpMessage = "The Steam account username to log out.")]
public string Username { get; set; } = string.Empty;
protected override async Task ProcessRecordAsync(CancellationToken cancellationToken)
{
var steamCmdService = SteamServicesProvider.GetSteamCmdService(SessionState);
try
{
var status = await steamCmdService.LogoutAsync(Username);
WriteObject(status);
}
catch (Exception ex)
{
WriteError(new ErrorRecord(ex, "LogoutError", ErrorCategory.OperationStopped, null));
}
}
}