diff --git a/src/code/ArchitectureCompleter.cs b/src/code/ArchitectureCompleter.cs new file mode 100644 index 0000000..426456e --- /dev/null +++ b/src/code/ArchitectureCompleter.cs @@ -0,0 +1,48 @@ +// Copyright (c) Thomas Nieto - All Rights Reserved +// You may use, distribute and modify this code under the +// terms of the MIT license. + +using System.Collections; +using System.Collections.Generic; +using System.Management.Automation; +using System.Management.Automation.Language; + +namespace AnyPackage.Provider.DotNet +{ + public sealed class ArchitectureCompleter : IArgumentCompleter + { + private static string[] architectures = new string[] + { + "android-arm64", + "ios-arm64", + "linux-arm", + "linux-arm64", + "linux-bionic-arm64", + "linux-musl-arm64", + "linux-musl-x64", + "linux-x64", + "osx-arm64", + "osx-x64", + "win-arm64", + "win-x64", + "win-x86" + }; + + public IEnumerable CompleteArgument(string commandName, + string parameterName, + string wordToComplete, + CommandAst commandAst, + IDictionary fakeBoundParameters) + { + var wildcard = new WildcardPattern(wordToComplete + "*", WildcardOptions.IgnoreCase); + + foreach (var arch in architectures) + { + if (wildcard.IsMatch(arch)) + { + yield return new CompletionResult(arch, arch, CompletionResultType.ParameterValue, arch); + } + } + } + } +} diff --git a/src/code/InstallPackageDynamicParameters.cs b/src/code/InstallPackageDynamicParameters.cs new file mode 100644 index 0000000..3175eba --- /dev/null +++ b/src/code/InstallPackageDynamicParameters.cs @@ -0,0 +1,20 @@ +// Copyright (c) Thomas Nieto - All Rights Reserved +// You may use, distribute and modify this code under the +// terms of the MIT license. + +using System.Management.Automation; + +namespace AnyPackage.Provider.DotNet +{ + public sealed class InstallPackageDynamicParameters + { + [Parameter] + [ArgumentCompleter(typeof(ArchitectureCompleter))] + [ValidateNotNullOrEmpty] + public string Architecture { get; set; } = string.Empty; + + [Parameter] + [ValidateNotNullOrEmpty] + public string Framework { get; set; } = string.Empty; + } +} diff --git a/src/code/ToolProvider.cs b/src/code/ToolProvider.cs index 449a948..5745ce2 100644 --- a/src/code/ToolProvider.cs +++ b/src/code/ToolProvider.cs @@ -11,6 +11,21 @@ namespace AnyPackage.Provider.DotNet [PackageProvider(".NET Tool")] public class ToolProvider : PackageProvider, IFindPackage, IGetPackage, IInstallPackage, IUpdatePackage, IUninstallPackage { + protected override object? GetDynamicParameters(string commandName) + { + switch (commandName) + { + case "Install-Package": + return new InstallPackageDynamicParameters(); + + case "Update-Package": + return new UpdatePackageDynamicParameters(); + + default: + return null; + } + } + public void FindPackage(PackageRequest request) { if (request.Name == "*") @@ -127,6 +142,21 @@ public void InstallPackage(PackageRequest request) args += " --prerelease"; } + if (request.DynamicParameters is not null) + { + var dynamicParameters = request.DynamicParameters as InstallPackageDynamicParameters; + + if (dynamicParameters is not null && dynamicParameters.Architecture != "") + { + args += $" --arch {dynamicParameters.Architecture}"; + } + + if (dynamicParameters is not null && dynamicParameters.Framework != "") + { + args += $" --framework {dynamicParameters.Framework}"; + } + } + InvokeDotNet(request, args); } @@ -151,6 +181,16 @@ public void UpdatePackage(PackageRequest request) args += " --prerelease"; } + if (request.DynamicParameters is not null) + { + var dynamicParameters = request.DynamicParameters as UpdatePackageDynamicParameters; + + if (dynamicParameters is not null && dynamicParameters.Framework != "") + { + args += $" --framework {dynamicParameters.Framework}"; + } + } + InvokeDotNet(request, args); } diff --git a/src/code/UpdatePackageDynamicParameters.cs b/src/code/UpdatePackageDynamicParameters.cs new file mode 100644 index 0000000..ab3530a --- /dev/null +++ b/src/code/UpdatePackageDynamicParameters.cs @@ -0,0 +1,15 @@ +// Copyright (c) Thomas Nieto - All Rights Reserved +// You may use, distribute and modify this code under the +// terms of the MIT license. + +using System.Management.Automation; + +namespace AnyPackage.Provider.DotNet +{ + public sealed class UpdatePackageDynamicParameters + { + [Parameter] + [ValidateNotNullOrEmpty] + public string Framework { get; set; } = string.Empty; + } +}