@@ -10,8 +10,7 @@ internal static class CmdletExtensions
1010{
1111 public static bool IsWhatIf ( this PSCmdlet cmdlet )
1212 {
13- if ( cmdlet is null )
14- throw new ArgumentNullException ( nameof ( cmdlet ) ) ;
13+ ArgumentNullException . ThrowIfNull ( cmdlet ) ;
1514
1615 return cmdlet . MyInvocation . BoundParameters . TryGetValue ( "WhatIf" , out var whatIf )
1716 ? whatIf is ( SwitchParameter { IsPresent : true } or true )
@@ -20,13 +19,21 @@ public static bool IsWhatIf(this PSCmdlet cmdlet)
2019
2120 public static string GetCurrentPath ( this PSCmdlet cmdlet )
2221 {
23- if ( cmdlet is null )
24- throw new ArgumentNullException ( nameof ( cmdlet ) ) ;
22+ ArgumentNullException . ThrowIfNull ( cmdlet ) ;
2523
2624 return cmdlet . SessionState . Path . CurrentFileSystemLocation . Path ;
2725 }
2826
29- private static readonly string [ ] HostTag = [ "PSHOST" ] ;
27+ public static string GetFullPath ( this PSCmdlet cmdlet , string ? path = null )
28+ {
29+ ArgumentNullException . ThrowIfNull ( cmdlet ) ;
30+
31+ path ??= "" ;
32+
33+ return Path . IsPathFullyQualified ( path )
34+ ? path
35+ : Path . GetFullPath ( path , basePath : cmdlet . GetCurrentPath ( ) ) ;
36+ }
3037
3138 /// <summary>
3239 /// Writes the specified message as a host information message.
@@ -77,4 +84,6 @@ public static void WriteHost(
7784
7885 cmdlet . WriteInformation ( data , HostTag ) ;
7986 }
87+
88+ private static readonly string [ ] HostTag = [ "PSHOST" ] ;
8089}
0 commit comments