summaryrefslogtreecommitdiff
path: root/SetUser.cs
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2026-05-08 01:28:31 +1000
committerJake Mannens <jake@asger.xyz>2026-05-08 01:28:31 +1000
commit8ef09f9fed656bacc3a25e790796e9f144a5fac8 (patch)
treedb940e9fe93eaf7cb226037d8d7ab1b1f6704c78 /SetUser.cs
parent7984d2ecd4bdba7061429f98fdfae88f44f4a358 (diff)
v0.14av0.14a
Diffstat (limited to 'SetUser.cs')
-rw-r--r--SetUser.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/SetUser.cs b/SetUser.cs
new file mode 100644
index 0000000..93af581
--- /dev/null
+++ b/SetUser.cs
@@ -0,0 +1,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);
+ }
+}