summaryrefslogtreecommitdiff
path: root/GetTagDefinition.cs
blob: 9d33366b8b0171ea10dfbd3544c8e210732d5e4c (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 HyperBooru.ApiModels;
using System.Management.Automation;

namespace HyperBooru.PowerShell;

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

    [Parameter(Position = 1, Mandatory = true, ParameterSetName = "AllTags")]
    public SwitchParameter All { get; set; }

    [Parameter(Position = 1, Mandatory = true, ParameterSetName = "IndividualTag")]
    public Guid TagDefinitionId { get; set; }

    protected override void ProcessRecord() {
        var tagDefinitions = Array.Empty<TagDefinition>();
        switch(ParameterSetName) {
            case "AllTags":
                tagDefinitions = Session.Tag.GetTagDefinitionAsync()
                    .GetAwaiter()
                    .GetResult();
                break;
            case "IndividualTag":
                tagDefinitions = [ Session.Tag.GetTagDefinitionAsync(TagDefinitionId)
                    .GetAwaiter()
                    .GetResult() ];
                break;
        }

        if(tagDefinitions?.Count() > 0)
            foreach(var td in tagDefinitions)
                WriteObject(td);
    }
}