summaryrefslogtreecommitdiff
path: root/GetUser.cs
blob: 63c5af7776461ebf91984abec6f4c7e990c7b1ce (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
using HyperBooru.ApiClient;
using System.Management.Automation;

namespace HyperBooru.PowerShell;

[Alias("ghbu")]
[Cmdlet(VerbsCommon.Get, "HyperBooruUser")]
public class GetUserCmdlet : PSCmdlet {
    [Parameter(Position = 0, Mandatory = true)]
    public HBSession Session { get; set; }

    [Parameter(Position = 1)]
    public Guid? UserId { get; set; }

    protected override void ProcessRecord() {
        ApiModels.User[] users;

        if(UserId is not null)
            users = [ Session.User.GetUserAsync((Guid) UserId).GetAwaiter().GetResult() ];
        else
            users = Session.User.GetAllUsersAsync().GetAwaiter().GetResult();

        foreach(var u in users)
            WriteObject(u);
    }
}