summaryrefslogtreecommitdiff
path: root/SetUser.cs
blob: cf13c7ff313af23e40d0444d6d4e226927ff63d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Management.Automation;
using System.Security;

namespace HyperBooru.PowerShell;

[Alias("shbu")]
[Cmdlet(VerbsCommon.Set, "HyperBooruUser")]
public class SetUserCmdlet : SessionCmdlet {
    [Parameter(Position = 1, Mandatory = true)]
    public Guid UserId { get; set; }

    [Parameter(Position = 2)]
    public string? Username { get; set; }

    [Parameter(Position = 3)]
    public SecureString? Password { get; set; }

    protected override void ProcessRecord() {
        if(Username is null && Password is null) {
            ThrowTerminatingError(new(
                new ArgumentException("Both Username and Password cannot be null"),
                "ArgumentException",
                ErrorCategory.InvalidArgument,
                null));
            return;
        }

        var user = Session.User.UpdateUserAsync(UserId, Username, Password?.ToInsecureString())
            .GetAwaiter()
            .GetResult();

        WriteObject(user);
    }
}