diff options
| author | Jake Mannens <jake@asger.xyz> | 2026-05-18 17:01:02 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2026-05-19 03:29:47 +1000 |
| commit | 07cfbfdb92890188cc0bed120acb1fcbf72d34db (patch) | |
| tree | 7beaf4ccf29d3060ef10e1c293a5ad6620535256 | |
| parent | ab46387d4d02e30b171a7c2fa07947b41ec691a0 (diff) | |
Added default global fallback session context
| -rw-r--r-- | AddImplicitTag.cs | 10 | ||||
| -rw-r--r-- | AddMediaTag.cs | 8 | ||||
| -rw-r--r-- | ConnectSession.cs | 2 | ||||
| -rw-r--r-- | DisconnectSession.cs | 10 | ||||
| -rw-r--r-- | GetMedia.cs | 10 | ||||
| -rw-r--r-- | GetMediaTag.cs | 8 | ||||
| -rw-r--r-- | GetTagDefinition.cs | 8 | ||||
| -rw-r--r-- | GetUploadedFile.cs | 8 | ||||
| -rw-r--r-- | GetUser.cs | 8 | ||||
| -rw-r--r-- | NewTagDefinition.cs | 8 | ||||
| -rw-r--r-- | NewUser.cs | 8 | ||||
| -rw-r--r-- | PublishMedia.cs | 8 | ||||
| -rw-r--r-- | RemoveImplicitTag.cs | 10 | ||||
| -rw-r--r-- | RemoveMediaTag.cs | 8 | ||||
| -rw-r--r-- | RemoveTagDefinition.cs | 8 | ||||
| -rw-r--r-- | RemoveUser.cs | 8 | ||||
| -rw-r--r-- | SessionCmdlet.cs | 16 | ||||
| -rw-r--r-- | SetImplicitTag.cs | 10 | ||||
| -rw-r--r-- | SetMediaTag.cs | 8 | ||||
| -rw-r--r-- | SetTagDefinition.cs | 8 | ||||
| -rw-r--r-- | SetUser.cs | 8 |
21 files changed, 72 insertions, 108 deletions
diff --git a/AddImplicitTag.cs b/AddImplicitTag.cs index 50f6cfc..e98778a 100644 --- a/AddImplicitTag.cs +++ b/AddImplicitTag.cs @@ -1,14 +1,12 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("ahbit")] [Cmdlet(VerbsCommon.Add, "HyperBooruImplicitTag")] -public class AddImplicitTagCmdlet : PSCmdlet { - [Parameter(Mandatory = true)] public required HBSession Session { get; set; } - [Parameter(Mandatory = true)] public required Guid TagDefinitionId { get; set; } - [Parameter(Mandatory = true)] public required Guid[] ImplicitTagId { get; set; } +public class AddImplicitTagCmdlet : SessionCmdlet { + [Parameter(Mandatory = true)] public required Guid TagDefinitionId { get; set; } + [Parameter(Mandatory = true)] public required Guid[] ImplicitTagId { get; set; } protected override void ProcessRecord() => Session.Tag.AddImplicitTagsAsync(TagDefinitionId, ImplicitTagId) diff --git a/AddMediaTag.cs b/AddMediaTag.cs index 35541e4..df2c39d 100644 --- a/AddMediaTag.cs +++ b/AddMediaTag.cs @@ -1,14 +1,10 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("ahbmt")] [Cmdlet(VerbsCommon.Add, "HyperBooruMediaTag")] -public class AddMediaTagCmdlet : PSCmdlet { - [Parameter(Position = 0, Mandatory = true)] - public required HBSession Session { get; set; } - +public class AddMediaTagCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true)] public Guid MediaId { get; set; } diff --git a/ConnectSession.cs b/ConnectSession.cs index 7590408..e8034fc 100644 --- a/ConnectSession.cs +++ b/ConnectSession.cs @@ -30,6 +30,8 @@ public class ConnectSessionCmdlet : PSCmdlet { targetObject: null)); } + SessionCmdlet.GlobalSession = session; + WriteVerbose($"Successfully logged in to {Host}"); WriteObject(session); } diff --git a/DisconnectSession.cs b/DisconnectSession.cs new file mode 100644 index 0000000..222b00e --- /dev/null +++ b/DisconnectSession.cs @@ -0,0 +1,10 @@ +using System.Management.Automation; + +namespace HyperBooru.PowerShell; + +[Alias("dchbs")] +[Cmdlet(VerbsCommunications.Disconnect, "HyperBooruSession")] +public class DisconnectSessionCmdlet : PSCmdlet { + protected override void BeginProcessing() => + SessionCmdlet.GlobalSession = null; +} diff --git a/GetMedia.cs b/GetMedia.cs index b01f38e..e45ae3a 100644 --- a/GetMedia.cs +++ b/GetMedia.cs @@ -1,15 +1,11 @@ -using HyperBooru.ApiClient; -using HyperBooru.ApiModels; +using HyperBooru.ApiModels; using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("ghbm")] [Cmdlet(VerbsCommon.Get, "HyperBooruMedia")] -public class GetMediaCmdlet : PSCmdlet { - [Parameter(Mandatory = true)] - public HBSession Session { get; set; } - +public class GetMediaCmdlet : SessionCmdlet { [Parameter] public SwitchParameter SelectIngest { get; set; } [Parameter] @@ -19,7 +15,7 @@ public class GetMediaCmdlet : PSCmdlet { [Parameter] public int Count { get; set; } = 50; [Parameter] - public ApiModels.SortOrder SortOrder { get; set; } + public SortOrder SortOrder { get; set; } [Parameter(ParameterSetName = "All", Mandatory = true)] public SwitchParameter All { get; set; } [Parameter(ParameterSetName = "TagId", Mandatory = true)] diff --git a/GetMediaTag.cs b/GetMediaTag.cs index 90d9835..638a85c 100644 --- a/GetMediaTag.cs +++ b/GetMediaTag.cs @@ -1,14 +1,10 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("ghbmt")] [Cmdlet(VerbsCommon.Get, "HyperBooruMediaTag")] -public class GetMediaTagCmdlet : PSCmdlet { - [Parameter(Position = 0, Mandatory = true)] - public required HBSession Session { get; set; } - +public class GetMediaTagCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true)] public Guid MediaId { get; set; } diff --git a/GetTagDefinition.cs b/GetTagDefinition.cs index 9d33366..916f1b7 100644 --- a/GetTagDefinition.cs +++ b/GetTagDefinition.cs @@ -1,15 +1,11 @@ -using HyperBooru.ApiClient; -using HyperBooru.ApiModels; +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; } - +public class GetTagDefinitionCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true, ParameterSetName = "AllTags")] public SwitchParameter All { get; set; } diff --git a/GetUploadedFile.cs b/GetUploadedFile.cs index ce9c7d9..ef77765 100644 --- a/GetUploadedFile.cs +++ b/GetUploadedFile.cs @@ -1,14 +1,10 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("ghbuf")] [Cmdlet(VerbsCommon.Get, "HyperBooruUploadedFile")] -public class GetUploadedFileCmdlet : PSCmdlet { - [Parameter(Position = 0, Mandatory = true)] - public HBSession Session { get; set; } - +public class GetUploadedFileCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true)] public Guid MediaId { get; set; } @@ -1,14 +1,10 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +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; } - +public class GetUserCmdlet : SessionCmdlet { [Parameter(Position = 1)] public Guid? UserId { get; set; } diff --git a/NewTagDefinition.cs b/NewTagDefinition.cs index c1fd971..dade4ba 100644 --- a/NewTagDefinition.cs +++ b/NewTagDefinition.cs @@ -1,15 +1,11 @@ -using HyperBooru.ApiClient; -using HyperBooru.ApiModels; +using HyperBooru.ApiModels; using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("nhbtd")] [Cmdlet(VerbsCommon.New, "HyperBooruTagDefinition")] -public class NewTagDefinitionCmdlet : PSCmdlet { - [Parameter(Mandatory = true)] - public required HBSession Session { get; set; } - +public class NewTagDefinitionCmdlet : SessionCmdlet { [Parameter] public string? Namespace { get; set; } [Parameter(Mandatory = true)] public required string Name { get; set; } [Parameter] public string? Alias { get; set; } @@ -1,15 +1,11 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; using System.Security; namespace HyperBooru.PowerShell; [Alias("nhbu")] [Cmdlet(VerbsCommon.New, "HyperBooruUser")] -public class NewUserCmdlet : PSCmdlet { - [Parameter(Position = 0, Mandatory = true)] - public HBSession Session { get; set; } - +public class NewUserCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true)] public string Username { get; set; } diff --git a/PublishMedia.cs b/PublishMedia.cs index 523b00f..003b48a 100644 --- a/PublishMedia.cs +++ b/PublishMedia.cs @@ -1,14 +1,10 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("pbhbm")] [Cmdlet(VerbsData.Publish, "HyperBooruMedia")] -public class PublishMediaCmdlet : PSCmdlet { - [Parameter(Position = 0, Mandatory = true)] - public HBSession Session { get; set; } - +public class PublishMediaCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true)] public string Path { get; set; } diff --git a/RemoveImplicitTag.cs b/RemoveImplicitTag.cs index 7d156ab..067a750 100644 --- a/RemoveImplicitTag.cs +++ b/RemoveImplicitTag.cs @@ -1,14 +1,12 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("rhbit")] [Cmdlet(VerbsCommon.Remove, "HyperBooruImplicitTag")] -public class RemoveImplicitTagCmdlet : PSCmdlet { - [Parameter(Mandatory = true)] public required HBSession Session { get; set; } - [Parameter(Mandatory = true)] public required Guid TagDefinitionId { get; set; } - [Parameter(Mandatory = true)] public required Guid[] ImplicitTagId { get; set; } +public class RemoveImplicitTagCmdlet : SessionCmdlet { + [Parameter(Mandatory = true)] public required Guid TagDefinitionId { get; set; } + [Parameter(Mandatory = true)] public required Guid[] ImplicitTagId { get; set; } protected override void ProcessRecord() => Session.Tag.DeleteImplicitTagAsync(TagDefinitionId, ImplicitTagId) diff --git a/RemoveMediaTag.cs b/RemoveMediaTag.cs index d41980d..d9d0b31 100644 --- a/RemoveMediaTag.cs +++ b/RemoveMediaTag.cs @@ -1,14 +1,10 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("rhbmt")] [Cmdlet(VerbsCommon.Remove, "HyperBooruMediaTag")] -public class RemoveMediaTagCmdlet : PSCmdlet { - [Parameter(Position = 0, Mandatory = true)] - public required HBSession Session { get; set; } - +public class RemoveMediaTagCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true)] public Guid MediaId { get; set; } diff --git a/RemoveTagDefinition.cs b/RemoveTagDefinition.cs index e28d7f9..c7eeddb 100644 --- a/RemoveTagDefinition.cs +++ b/RemoveTagDefinition.cs @@ -1,13 +1,11 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("rhbtd")] [Cmdlet(VerbsCommon.Remove, "HyperBooruTagDefinition")] -public class RemoveTagDefinitionCmdlet : PSCmdlet { - [Parameter(Mandatory = true)] public required HBSession Session { get; set; } - [Parameter(Mandatory = true)] public required Guid TagDefinitionId { get; set; } +public class RemoveTagDefinitionCmdlet : SessionCmdlet { + [Parameter(Mandatory = true)] public required Guid TagDefinitionId { get; set; } protected override void ProcessRecord() => Session.Tag.DeleteTagDefinitionAsync(TagDefinitionId) diff --git a/RemoveUser.cs b/RemoveUser.cs index 0e28675..2ec64ed 100644 --- a/RemoveUser.cs +++ b/RemoveUser.cs @@ -1,14 +1,10 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("rhbu")] [Cmdlet(VerbsCommon.Remove, "HyperBooruUser")] -public class RemoveUserCmdlet : PSCmdlet { - [Parameter(Position = 0, Mandatory = true)] - public HBSession Session { get; set; } - +public class RemoveUserCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true)] public Guid UserId { get; set; } diff --git a/SessionCmdlet.cs b/SessionCmdlet.cs new file mode 100644 index 0000000..d823383 --- /dev/null +++ b/SessionCmdlet.cs @@ -0,0 +1,16 @@ +using HyperBooru.ApiClient; +using System.Management.Automation; + +namespace HyperBooru.PowerShell; + +public abstract class SessionCmdlet : PSCmdlet { + [Parameter(Position = 0)] + public HBSession Session { + get => session ?? GlobalSession!; + set => session = value; + } + + internal static HBSession? GlobalSession { get; set; } + + private HBSession? session = null; +} diff --git a/SetImplicitTag.cs b/SetImplicitTag.cs index 8d11f1c..409b975 100644 --- a/SetImplicitTag.cs +++ b/SetImplicitTag.cs @@ -1,14 +1,12 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("shbit")] [Cmdlet(VerbsCommon.Set, "HyperBooruImplicitTag")] -public class SetImplicitTagCmdlet : PSCmdlet { - [Parameter(Mandatory = true)] public required HBSession Session { get; set; } - [Parameter(Mandatory = true)] public required Guid TagDefinitionId { get; set; } - [Parameter(Mandatory = true)] public required Guid[] ImplicitTagId { get; set; } +public class SetImplicitTagCmdlet : SessionCmdlet { + [Parameter(Mandatory = true)] public required Guid TagDefinitionId { get; set; } + [Parameter(Mandatory = true)] public required Guid[] ImplicitTagId { get; set; } protected override void ProcessRecord() => Session.Tag.ReplaceImplicitTagsAsync(TagDefinitionId, ImplicitTagId) diff --git a/SetMediaTag.cs b/SetMediaTag.cs index 8931991..4ff016f 100644 --- a/SetMediaTag.cs +++ b/SetMediaTag.cs @@ -1,14 +1,10 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("shbmt")] [Cmdlet(VerbsCommon.Set, "HyperBooruMediaTag")] -public class SetMediaTagCmdlet : PSCmdlet { - [Parameter(Position = 0, Mandatory = true)] - public required HBSession Session { get; set; } - +public class SetMediaTagCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true)] public Guid MediaId { get; set; } diff --git a/SetTagDefinition.cs b/SetTagDefinition.cs index 51a18f4..b1ef14b 100644 --- a/SetTagDefinition.cs +++ b/SetTagDefinition.cs @@ -1,15 +1,11 @@ -using HyperBooru.ApiClient; -using HyperBooru.ApiModels; +using HyperBooru.ApiModels; using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("shbtd")] [Cmdlet(VerbsCommon.Set, "HyperBooruTagDefinition")] -public class SetTagDefinitionCmdlet : PSCmdlet { - [Parameter(Mandatory = true)] - public required HBSession Session { get; set; } - +public class SetTagDefinitionCmdlet : SessionCmdlet { [Parameter(Mandatory = true)] public required Guid TagDefinitionId { get; set; } @@ -1,15 +1,11 @@ -using HyperBooru.ApiClient; -using System.Management.Automation; +using System.Management.Automation; using System.Security; namespace HyperBooru.PowerShell; [Alias("shbu")] [Cmdlet(VerbsCommon.Set, "HyperBooruUser")] -public class SetUserCmdlet : PSCmdlet { - [Parameter(Position = 0, Mandatory = true)] - public HBSession Session { get; set; } - +public class SetUserCmdlet : SessionCmdlet { [Parameter(Position = 1, Mandatory = true)] public Guid UserId { get; set; } |
