summaryrefslogtreecommitdiff
path: root/GetTagDefinition.cs
diff options
context:
space:
mode:
Diffstat (limited to 'GetTagDefinition.cs')
-rw-r--r--GetTagDefinition.cs38
1 files changed, 38 insertions, 0 deletions
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<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);
+ }
+}