From 7984d2ecd4bdba7061429f98fdfae88f44f4a358 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Fri, 25 Aug 2023 15:47:14 +1000 Subject: v0.13a --- GetTagDefinition.cs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 GetTagDefinition.cs (limited to 'GetTagDefinition.cs') diff --git a/GetTagDefinition.cs b/GetTagDefinition.cs new file mode 100644 index 0000000..9d33366 --- /dev/null +++ b/GetTagDefinition.cs @@ -0,0 +1,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(); + 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); + } +} -- cgit v1.3