Skip to content

Add alias for LiteralPath parameter for all cmdlets #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Command/ImportMamlCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class ImportMamlHelpCommand : PSCmdlet
public string[] Path { get; set; } = new string[0];

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "LiteralPath")]
[Alias("PSPath", "LP")]
[ValidateNotNullOrEmpty]
public string[] LiteralPath { get; set; } = new string[0];

Expand Down
1 change: 1 addition & 0 deletions src/Command/ImportMarkdownCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class ImportMarkdownHelpCommand : PSCmdlet
public string[] Path { get; set; } = Array.Empty<string>();

[Parameter(Mandatory=true, ValueFromPipeline=true, ParameterSetName= "LiteralPath")]
[Alias("PSPath", "LP")]
[ValidateNotNullOrEmpty]
public string[] LiteralPath { get; set; } = Array.Empty<string>();

Expand Down
1 change: 1 addition & 0 deletions src/Command/ImportModuleFileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class ImportMarkdownModuleFileCommand : PSCmdlet
public string[] Path { get; set; } = Array.Empty<string>();

[Parameter(Mandatory=true, ValueFromPipeline=true, ParameterSetName= "LiteralPath")]
[Alias("PSPath", "LP")]
[ValidateNotNullOrEmpty]
public string[] LiteralPath { get; set; } = Array.Empty<string>();

Expand Down
1 change: 1 addition & 0 deletions src/Command/ImportYamlCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public string[] Path
/// An array of literal paths to get the markdown metadata from.
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = "LiteralPath")]
[Alias("PSPath", "LP")]
public string[] LiteralPath
{
get
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ImportYamlModuleFileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public sealed class ImportYamlModuleFileCommand : PSCmdlet
public string[] Path { get; set; } = Array.Empty<string>();

[Parameter(Mandatory=true, ValueFromPipeline=true, ParameterSetName= "LiteralPath")]
[Alias("PSPath", "LP")]
[ValidateNotNullOrEmpty]
public string[] LiteralPath { get; set; } = Array.Empty<string>();

Expand Down Expand Up @@ -61,7 +62,7 @@ protected override void ProcessRecord()
}
continue;
}

if (YamlUtils.TryReadModuleFile(path, out ModuleFileInfo? moduleFileInfo, out Exception? deserializationError))
{
WriteObject(moduleFileInfo);
Expand Down
1 change: 1 addition & 0 deletions src/Command/Measure-PlatyPSMarkdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class MeasurePlatyPSMarkdown : PSCmdlet
public string[] Path { get; set; } = Array.Empty<string>();

[Parameter(Mandatory=true, ValueFromPipeline=true, ParameterSetName= "LiteralPath")]
[Alias("PSPath", "LP")]
[ValidateNotNullOrEmpty]
public string[] LiteralPath { get; set; } = Array.Empty<string>();

Expand Down
5 changes: 3 additions & 2 deletions src/Command/Update-CommandHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public sealed class UpdateHelpCommand : PSCmdlet
public string[] Path { get; set; } = Array.Empty<string>();

[Parameter(Mandatory=true, ValueFromPipeline=true, ParameterSetName= "LiteralPath")]
[Alias("PSPath", "LP")]
[ValidateNotNullOrEmpty]
public string[] LiteralPath { get; set; } = Array.Empty<string>();

Expand Down Expand Up @@ -65,7 +66,7 @@ protected override void ProcessRecord()
var cmdInfo = SessionState.InvokeCommand.GetCommand(commandName, CommandTypes.Function|CommandTypes.Filter|CommandTypes.Cmdlet);
if (cmdInfo is null)
{
var err = new ErrorRecord(new CommandNotFoundException(commandName), "UpdateMarkdownCommandHelp,CommandNotFound", ErrorCategory.ObjectNotFound, commandName);
var err = new ErrorRecord(new CommandNotFoundException(commandName), "UpdateMarkdownCommandHelp,CommandNotFound", ErrorCategory.ObjectNotFound, commandName);
err.ErrorDetails = new($"Did you import the module which includes '{commandName}'?");
WriteError(err);
continue;
Expand All @@ -74,7 +75,7 @@ protected override void ProcessRecord()
var helpObjectFromCmdlet = new TransformCommand(transformSettings).Transform(cmdInfo);
if (helpObjectFromCmdlet is null)
{
var err = new ErrorRecord(new InvalidOperationException(commandName), "UpdateMarkdownCommandHelp,CmdletConversion", ErrorCategory.InvalidResult, commandName);
var err = new ErrorRecord(new InvalidOperationException(commandName), "UpdateMarkdownCommandHelp,CmdletConversion", ErrorCategory.InvalidResult, commandName);
err.ErrorDetails = new($"Could not convert {commandName} to CommandHelp.");
WriteError(err);
continue;
Expand Down
5 changes: 3 additions & 2 deletions src/Command/Update-MarkdownCommandHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class UpdateMarkdownHelpCommand : PSCmdlet
public string[] Path { get; set; } = Array.Empty<string>();

[Parameter(Mandatory=true, ValueFromPipeline=true, ParameterSetName= "LiteralPath")]
[Alias("PSPath", "LP")]
[ValidateNotNullOrEmpty]
public string[] LiteralPath { get; set; } = Array.Empty<string>();

Expand Down Expand Up @@ -91,7 +92,7 @@ protected override void ProcessRecord()
var cmdInfo = PowerShellAPI.GetCommandInfo(commandName);
if (cmdInfo is null)
{
var err = new ErrorRecord(new CommandNotFoundException(commandName), "UpdateMarkdownCommandHelp,CommandNotFound", ErrorCategory.ObjectNotFound, commandName);
var err = new ErrorRecord(new CommandNotFoundException(commandName), "UpdateMarkdownCommandHelp,CommandNotFound", ErrorCategory.ObjectNotFound, commandName);
err.ErrorDetails = new($"Did you import the module which includes '{commandName}'?");
WriteError(err);
continue;
Expand All @@ -100,7 +101,7 @@ protected override void ProcessRecord()
var helpObjectFromCmdlet = new TransformCommand(transformSettings).Transform(cmdInfo.First());
if (helpObjectFromCmdlet is null)
{
var err = new ErrorRecord(new InvalidOperationException(commandName), "UpdateMarkdownCommandHelp,CmdletConversion", ErrorCategory.InvalidResult, commandName);
var err = new ErrorRecord(new InvalidOperationException(commandName), "UpdateMarkdownCommandHelp,CmdletConversion", ErrorCategory.InvalidResult, commandName);
err.ErrorDetails = new($"Could not convert {commandName} to CommandHelp.");
WriteError(err);
continue;
Expand Down
1 change: 1 addition & 0 deletions src/Command/UpdateMarkdownModuleFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed class UpdateMarkdownModuleFileCommand : PSCmdlet
public string Path { get; set; } = string.Empty;

[Parameter(Mandatory = true, ParameterSetName = "literalpath")]
[Alias("PSPath", "LP")]
public string LiteralPath { get; set; } = string.Empty;

[Parameter(ValueFromPipeline = true, Mandatory = true, Position = 1)]
Expand Down
7 changes: 5 additions & 2 deletions test/Pester/Cmdlet.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ Describe "Miscellaneous cmdlet tests" {
}
) {
param ($cmdlet)
$cmdlet.Parameters['LiteralPath'] | Should -Not -BeNullOrEmpty
$param = $cmdlet.Parameters['LiteralPath']
$param | Should -Not -BeNullOrEmpty
$param.Aliases | Should -Contain "PSPath"
$param.Aliases | Should -Contain "LP"
}
}

Expand Down Expand Up @@ -88,7 +91,7 @@ Describe "Miscellaneous cmdlet tests" {
Import-Module Microsoft.PowerShell.Archive
if (! $IsWindows) {
$skipTest = $true
return
return
}

$OutputPath = "$TestDrive\CabTesting"
Expand Down