summaryrefslogtreecommitdiff
path: root/SetUser.cs
diff options
context:
space:
mode:
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);
+ }
+}