summaryrefslogtreecommitdiff
path: root/RemoveMediaTag.cs
blob: de10611cf165c9420f5813826b76f3a3bc173940 (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
using System.Management.Automation;

namespace HyperBooru.PowerShell;

[Alias("rhbmt")]
[Cmdlet(VerbsCommon.Remove, "HyperBooruMediaTag")]
public class RemoveMediaTagCmdlet : SessionCmdlet {
    [Parameter(Position = 1, Mandatory = true)]
    public Guid MediaId { get; set; }

    [Parameter(Position = 2, Mandatory = true)]
    public Guid[] TagId { get; set; }

    protected override void ProcessRecord() {
        Session.Media.DeleteTagsAsync(MediaId, TagId)
            .GetAwaiter()
            .GetResult();

        var id   = MediaId.ToString().ToUpper();
        var tags = TagId
            .Order()
            .Distinct()
            .Select(t => t.ToString().ToUpper());

        WriteVerbose($"Removed tags {string.Join(", ", tags)} from media item {id}");
    }
}