diff options
| -rw-r--r-- | AddImplicitTag.cs | 21 | ||||
| -rw-r--r-- | AddMediaTag.cs | 19 | ||||
| -rw-r--r-- | ConnectSession.cs | 2 | ||||
| -rw-r--r-- | DisconnectSession.cs | 18 | ||||
| -rw-r--r-- | GetIngestStatistics.cs | 11 | ||||
| -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-- | HyperBooru.format.ps1xml | 187 | ||||
| -rw-r--r-- | HyperBooru.psd1 | 3 | ||||
| -rw-r--r-- | NewTagDefinition.cs | 8 | ||||
| -rw-r--r-- | NewUser.cs | 8 | ||||
| -rw-r--r-- | PowerShell.csproj | 5 | ||||
| -rw-r--r-- | PublishMedia.cs | 8 | ||||
| -rw-r--r-- | RemoveImplicitTag.cs | 22 | ||||
| -rw-r--r-- | RemoveMediaTag.cs | 19 | ||||
| -rw-r--r-- | RemoveTagDefinition.cs | 13 | ||||
| -rw-r--r-- | RemoveUser.cs | 10 | ||||
| -rw-r--r-- | SessionCmdlet.cs | 16 | ||||
| -rw-r--r-- | SetImplicitTag.cs | 21 | ||||
| -rw-r--r-- | SetMediaTag.cs | 19 | ||||
| -rw-r--r-- | SetTagDefinition.cs | 8 | ||||
| -rw-r--r-- | SetUser.cs | 8 |
25 files changed, 351 insertions, 117 deletions
diff --git a/AddImplicitTag.cs b/AddImplicitTag.cs index 50f6cfc..db2d0bf 100644 --- a/AddImplicitTag.cs +++ b/AddImplicitTag.cs @@ -1,17 +1,24 @@ -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() => + protected override void ProcessRecord() { Session.Tag.AddImplicitTagsAsync(TagDefinitionId, ImplicitTagId) .GetAwaiter() .GetResult(); + + var id = TagDefinitionId.ToString().ToUpper(); + var impl = ImplicitTagId + .Order() + .Distinct() + .Select(t => t.ToString().ToUpper()); + + WriteVerbose($"Added implicit tags {string.Join(", ", impl)} to tag {id}"); + } } diff --git a/AddMediaTag.cs b/AddMediaTag.cs index 35541e4..2ced119 100644 --- a/AddMediaTag.cs +++ b/AddMediaTag.cs @@ -1,22 +1,27 @@ -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; } [Parameter(Position = 2, Mandatory = true)] public Guid[] TagId { get; set; } - protected override void ProcessRecord() => + protected override void ProcessRecord() { Session.Media.AddTagsAsync(MediaId, TagId) .GetAwaiter() .GetResult(); + + var id = MediaId.ToString().ToUpper(); + var tags = TagId + .Order() + .Distinct() + .Select(t => t.ToString().ToUpper()); + + WriteVerbose($"Added tags {string.Join(", ", tags)} to media item {id}"); + } } 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..eccd9fe --- /dev/null +++ b/DisconnectSession.cs @@ -0,0 +1,18 @@ +using System.Management.Automation; + +namespace HyperBooru.PowerShell; + +[Alias("dchbs")] +[Cmdlet(VerbsCommunications.Disconnect, "HyperBooruSession")] +public class DisconnectSessionCmdlet : PSCmdlet { + protected override void BeginProcessing() { + var baseUri = SessionCmdlet.GlobalSession?.BaseUri; + + SessionCmdlet.GlobalSession = null; + + if(baseUri is not null) + WriteVerbose($"Successfully disconnected from {baseUri}"); + else + WriteVerbose($"No active sessions - nothing to disconnect"); + } +} diff --git a/GetIngestStatistics.cs b/GetIngestStatistics.cs new file mode 100644 index 0000000..0a61c1f --- /dev/null +++ b/GetIngestStatistics.cs @@ -0,0 +1,11 @@ +using System.Management.Automation; + +namespace HyperBooru.PowerShell; + +[Alias("ghbis")] +[Cmdlet(VerbsCommon.Get, "HyperBooruIngestStatistics")] +public class GetIngestStatisticsCmdlet : SessionCmdlet { + protected override void ProcessRecord() => + WriteObject( + Session.Statistics.GetIngestStatisticsAsync().GetAwaiter().GetResult()); +} 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/HyperBooru.format.ps1xml b/HyperBooru.format.ps1xml new file mode 100644 index 0000000..ab46bf5 --- /dev/null +++ b/HyperBooru.format.ps1xml @@ -0,0 +1,187 @@ +<?xml version="1.0" encoding="utf-8" ?> +<Configuration> + <ViewDefinitions> + + <View> + <Name>HBSessionDefinitionDefaultView</Name> + <ViewSelectedBy> + <TypeName>HyperBooru.ApiClient.HBSession</TypeName> + </ViewSelectedBy> + <TableControl> + <TableHeaders> + <TableColumnHeader> + <Label>BaseUri</Label> + </TableColumnHeader> + </TableHeaders> + <TableRowEntries> + <TableRowEntry> + <TableColumnItems> + <TableColumnItem> + <PropertyName>BaseUri</PropertyName> + </TableColumnItem> + </TableColumnItems> + </TableRowEntry> + </TableRowEntries> + </TableControl> + </View> + + <View> + <Name>TagDefinitionDefaultView</Name> + <ViewSelectedBy> + <TypeName>HyperBooru.ApiModels.TagDefinition</TypeName> + </ViewSelectedBy> + <TableControl> + <TableHeaders> + <TableColumnHeader> + <Label>TagDefinitionId</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Alias</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Namespace</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Name</Label> + </TableColumnHeader> + </TableHeaders> + <TableRowEntries> + <TableRowEntry> + <TableColumnItems> + <TableColumnItem> + <PropertyName>TagDefinitionId</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>Alias</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>Namespace</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>Name</PropertyName> + </TableColumnItem> + </TableColumnItems> + </TableRowEntry> + </TableRowEntries> + </TableControl> + </View> + + <View> + <Name>MediaDefaultView</Name> + <ViewSelectedBy> + <TypeName>HyperBooru.ApiModels.Media</TypeName> + </ViewSelectedBy> + <TableControl> + <TableHeaders> + <TableColumnHeader> + <Label>MediaId</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>ShortDescription</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>LongDescription</Label> + </TableColumnHeader> + </TableHeaders> + <TableRowEntries> + <TableRowEntry> + <TableColumnItems> + <TableColumnItem> + <PropertyName>MediaId</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>ShortDescription</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>LongDescription</PropertyName> + </TableColumnItem> + </TableColumnItems> + </TableRowEntry> + </TableRowEntries> + </TableControl> + </View> + + <View> + <Name>UserDefaultView</Name> + <ViewSelectedBy> + <TypeName>HyperBooru.ApiModels.User</TypeName> + </ViewSelectedBy> + <TableControl> + <TableHeaders> + <TableColumnHeader> + <Label>UserId</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Username</Label> + </TableColumnHeader> + </TableHeaders> + <TableRowEntries> + <TableRowEntry> + <TableColumnItems> + <TableColumnItem> + <PropertyName>UserId</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>Username</PropertyName> + </TableColumnItem> + </TableColumnItems> + </TableRowEntry> + </TableRowEntries> + </TableControl> + </View> + + <View> + <Name>UploadedFileDefaultView</Name> + <ViewSelectedBy> + <TypeName>HyperBooru.ApiModels.UploadedFile</TypeName> + </ViewSelectedBy> + <TableControl> + <TableHeaders> + <TableColumnHeader> + <Label>UploadedFileId</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>MediaId</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Checksum</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Path</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Filename</Label> + </TableColumnHeader> + <TableColumnHeader> + <Label>Length</Label> + </TableColumnHeader> + </TableHeaders> + <TableRowEntries> + <TableRowEntry> + <TableColumnItems> + <TableColumnItem> + <PropertyName>UploadedFileId</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>MediaId</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>Checksum</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>Path</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>Filename</PropertyName> + </TableColumnItem> + <TableColumnItem> + <PropertyName>Length</PropertyName> + </TableColumnItem> + </TableColumnItems> + </TableRowEntry> + </TableRowEntries> + </TableControl> + </View> + + </ViewDefinitions> +</Configuration> diff --git a/HyperBooru.psd1 b/HyperBooru.psd1 index 63ac453..f0f0605 100644 --- a/HyperBooru.psd1 +++ b/HyperBooru.psd1 @@ -1,6 +1,6 @@ @{ RootModule = 'HyperBooru.PowerShell.dll' - ModuleVersion = '0.17' + ModuleVersion = '0.18' CompatiblePSEditions = 'Core' PowershellVersion = '5.1' GUID = '627c3cbf-7fcc-41b3-9716-610b81ef1032' @@ -11,6 +11,7 @@ ProcessorArchitecture = 'MSIL' FunctionsToExport = '*' VariablesToExport = '*' + FormatsToProcess = 'HyperBooru.format.ps1xml' PrivateData = @{ PSData = @{ LicenseUri = 'https://www.gnu.org/licenses/gpl-3.0.en.html' 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/PowerShell.csproj b/PowerShell.csproj index 241f948..4ddcb95 100644 --- a/PowerShell.csproj +++ b/PowerShell.csproj @@ -9,7 +9,7 @@ <FileVersion>$(AssemblyVersion)</FileVersion>
<AssemblyTitle>HyperBooru.PowerShell</AssemblyTitle>
<Authors>Jake Mannens</Authors>
- <Version>0.17-alpha</Version>
+ <Version>0.18-alpha</Version>
</PropertyGroup>
<ItemGroup>
@@ -25,6 +25,9 @@ </ItemGroup>
<ItemGroup>
+ <None Update="HyperBooru.format.ps1xml">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
<None Update="HyperBooru.psd1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
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..a76c54f 100644 --- a/RemoveImplicitTag.cs +++ b/RemoveImplicitTag.cs @@ -1,17 +1,25 @@ -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() => + protected override void ProcessRecord() { Session.Tag.DeleteImplicitTagAsync(TagDefinitionId, ImplicitTagId) .GetAwaiter() .GetResult(); + + var id = TagDefinitionId.ToString().ToUpper(); + var impl = ImplicitTagId + .Order() + .Distinct() + .Select(t => t.ToString().ToUpper()); + + WriteVerbose( + $"Removed implicit tags {string.Join(", ", impl)} from tag {id}"); + } } diff --git a/RemoveMediaTag.cs b/RemoveMediaTag.cs index d41980d..de10611 100644 --- a/RemoveMediaTag.cs +++ b/RemoveMediaTag.cs @@ -1,22 +1,27 @@ -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; } [Parameter(Position = 2, Mandatory = true)] public Guid[] TagId { get; set; } - protected override void ProcessRecord() => + 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}"); + } } diff --git a/RemoveTagDefinition.cs b/RemoveTagDefinition.cs index e28d7f9..b0d4a11 100644 --- a/RemoveTagDefinition.cs +++ b/RemoveTagDefinition.cs @@ -1,16 +1,17 @@ -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() => + protected override void ProcessRecord() { Session.Tag.DeleteTagDefinitionAsync(TagDefinitionId) .GetAwaiter() .GetResult(); + + WriteVerbose($"Removed tag definition {TagDefinitionId.ToString().ToUpper()}"); + } } diff --git a/RemoveUser.cs b/RemoveUser.cs index 0e28675..5251103 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; } @@ -16,5 +12,7 @@ public class RemoveUserCmdlet : PSCmdlet { Session.User.DeleteUserAsync(UserId) .GetAwaiter() .GetResult(); + + WriteVerbose($"Removed user {UserId.ToString().ToUpper()}"); } } 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..bad10d1 100644 --- a/SetImplicitTag.cs +++ b/SetImplicitTag.cs @@ -1,17 +1,24 @@ -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() => + protected override void ProcessRecord() { Session.Tag.ReplaceImplicitTagsAsync(TagDefinitionId, ImplicitTagId) .GetAwaiter() .GetResult(); + + var id = TagDefinitionId.ToString().ToUpper(); + var impl = ImplicitTagId + .Order() + .Distinct() + .Select(t => t.ToString().ToUpper()); + + WriteVerbose($"Set implicit tags for {id} to {string.Join(", ", impl)}"); + } } diff --git a/SetMediaTag.cs b/SetMediaTag.cs index 8931991..dc2bbd7 100644 --- a/SetMediaTag.cs +++ b/SetMediaTag.cs @@ -1,22 +1,27 @@ -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; } [Parameter(Position = 2, Mandatory = true)] public Guid[] TagId { get; set; } - protected override void ProcessRecord() => + protected override void ProcessRecord() { Session.Media.ReplaceTagsAsync(MediaId, TagId) .GetAwaiter() .GetResult(); + + var id = MediaId.ToString().ToUpper(); + var tags = TagId + .Order() + .Distinct() + .Select(t => t.ToString().ToUpper()); + + WriteVerbose($"Set tags for media item {id} to {string.Join(", ", tags)}"); + } } 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; } |
