Merge pull request #85 from JunielKatarn/powershell-module

Add PowerShell support
This commit is contained in:
2026-02-13 01:51:47 +00:00
committed by GitHub
7 changed files with 203 additions and 10 deletions

View File

@@ -730,6 +730,9 @@ ij_scss_value_alignment = 0
indent_size = 2
ij_slim_keep_indents_on_empty_lines = false
[*.sln]
end_of_line = crlf
[*.twig]
ij_twig_keep_indents_on_empty_lines = false
ij_twig_spaces_inside_comments_delimiters = true

View File

@@ -7,11 +7,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.2"/>
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\plist-cil\plist-cil.csproj"/>
<ProjectReference Include="..\plist-cil\plist-cil.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1,152 @@
namespace Claunia.PropertyList.Shell;
using System;
using System.Collections.Generic;
using System.IO;
using System.Management.Automation;
[Cmdlet(VerbsData.ConvertFrom, "Plist")]
public class ConvertFromPlist : PSCmdlet
{
readonly List<byte> _inputBuffer = new();
#region Parameters
/// <summary>
/// Gets or sets the InputObject property.
/// Represents the byte stream input to be converted.
///
/// Sample usage:
/// Get-Content -AsByteStream 'file.plist' | ConvertFrom-Plist
/// </summary>
[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipeline = true,
ParameterSetName = "FromObject")]
[AllowEmptyString]
public byte InputObject { get; set; }
private FileInfo? _path;
[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true,
ParameterSetName = "FromPath")]
public FileInfo? Path
{
get => _path;
set
{
_path = new FileInfo(System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, value!.ToString()));
}
}
/// <summary>
/// Whether to return the result as a Claunia.PropertyList.NSObject instance.
/// </summary>
[Parameter]
public SwitchParameter AsNSObject { get; set; }
#endregion Parameters
#region Overrides
protected override void BeginProcessing()
{
WriteDebug($"Parameter set: {ParameterSetName}");
if (ParameterSetName != "FromPath")
return;
WriteDebug($"Setting current directory: {SessionState.Path.CurrentFileSystemLocation.Path}");
Environment.CurrentDirectory = SessionState.Path.CurrentFileSystemLocation.Path;
WriteDebug($"Current directory: {Environment.CurrentDirectory}");
}
protected override void ProcessRecord()
{
if (ParameterSetName != "FromObject")
return;
_inputBuffer.Add(InputObject);
}
protected override void EndProcessing()
{
NSObject plist;
switch (ParameterSetName)
{
case "FromPath":
plist = PropertyListParser.Parse(Path!.FullName);
break;
case "FromObject":
WriteDebug($"Buffer length: [{_inputBuffer.Count}]");
plist = PropertyListParser.Parse(_inputBuffer.ToArray());
break;
default:
throw new InvalidOperationException("Unknown parameter set");
}
if (AsNSObject.IsPresent)
{
WriteObject(plist);
return;
}
WriteObject(FromNSObject(plist));
}
#endregion Overrides
PSObject FromNSObject(NSObject value)
{
if (value == null)
return new(null);
switch(value)
{
case NSDictionary dict:
var result = new PSObject();
foreach(var key in dict.Keys)
{
result.Properties.Add(new PSNoteProperty(key.ToString(), FromNSObject(dict.ObjectForKey(key))));
}
return result;
case NSArray array:
var psArray = new object[array.Count];
int i = 0;
foreach (var element in array)
{
psArray[i++] = FromNSObject(element);
}
return new PSObject(psArray[..i]);
case NSNumber number:
switch(number.GetNSNumberType())
{
case NSNumber.BOOLEAN:
return new PSObject(number.ToBool());
case NSNumber.INTEGER:
return new PSObject(number.ToLong());
case NSNumber.REAL:
return new PSObject(number.ToDouble());
default:
throw new NotSupportedException("Unsupported NSNumber type");
}
case NSString:
return new PSObject(value.ToString());
case NSDate date:
return new PSObject(date.Date);
case NSData data:
return new PSObject(data.Bytes);
default:
throw new NotSupportedException($"Unsupported NSObject type: {value.GetType().FullName}");
}
}
}

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<RootNamespace>Claunia.PropertyList.Shell</RootNamespace>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Management.Automation" Version="7.1.7">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\plist-cil\plist-cil.csproj" />
</ItemGroup>
</Project>

View File

@@ -12,7 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
version.json = version.json
ChangeLog = ChangeLog
.editorconfig = .editorconfig
.gitignore = .gitignore
.gitignore = .gitignore
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "plist-cil", "plist-cil\plist-cil.csproj", "{2A906AEB-BDE0-4356-8114-064F80596C7D}"
@@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "plist-cil.test", "plist-cil
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "plist-cil.benchmark", "plist-cil.benchmark\plist-cil.benchmark.csproj", "{2AE44841-2E54-4310-843C-8DEE786E5052}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "plist-cil.shell", "plist-cil.shell\plist-cil.shell.csproj", "{C0692A99-3407-4E84-BB87-651978165798}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -81,6 +83,22 @@ Global
{2AE44841-2E54-4310-843C-8DEE786E5052}.Release|x64.Build.0 = Release|Any CPU
{2AE44841-2E54-4310-843C-8DEE786E5052}.Release|x86.ActiveCfg = Release|Any CPU
{2AE44841-2E54-4310-843C-8DEE786E5052}.Release|x86.Build.0 = Release|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Debug|ARM.ActiveCfg = Debug|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Debug|ARM.Build.0 = Debug|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Debug|x64.ActiveCfg = Debug|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Debug|x64.Build.0 = Debug|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Debug|x86.ActiveCfg = Debug|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Debug|x86.Build.0 = Debug|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Release|Any CPU.Build.0 = Release|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Release|ARM.ActiveCfg = Release|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Release|ARM.Build.0 = Release|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Release|x64.ActiveCfg = Release|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Release|x64.Build.0 = Release|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Release|x86.ActiveCfg = Release|Any CPU
{C0692A99-3407-4E84-BB87-651978165798}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -5,8 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
<PackageReference Include="xunit" Version="2.9.3"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -14,7 +14,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\plist-cil\plist-cil.csproj"/>
<ProjectReference Include="..\plist-cil\plist-cil.csproj" />
</ItemGroup>
<ItemGroup>
@@ -111,7 +111,7 @@
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}"/>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>

View File

@@ -45,12 +45,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115" PrivateAssets="all"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net462'">
<PackageReference Include="System.Memory" Version="4.6.0"/>
<PackageReference Include="System.Memory" Version="4.6.0" />
</ItemGroup>
<ItemGroup>