blob: 93af581710eb0c14ff31f5200efa661ee6b85cfb (
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
35
36
37
38
|
using HyperBooru.ApiClient;
using System.Management.Automation;
using System.Security;
namespace HyperBooru.PowerShell;
[Alias("shbu")]
[Cmdlet(VerbsCommon.Set, "HyperBooruUser")]
public class SetUserCmdlet : PSCmdlet {
[Parameter(Position = 0, Mandatory = true)]
public HBSession Session { get; set; }
[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);
}
}
|