Skip to content

Commit 4d85e61

Browse files
committed
Fix relative paths using wrong base directory.
1 parent a0c4eba commit 4d85e61

4 files changed

Lines changed: 21 additions & 14 deletions

File tree

PSql.Deploy/Commands/GetSqlMigrationsCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ private async Task ProcessRecordAsync()
8484
WriteObject(new Migration(migration));
8585
}
8686

87-
private static IReadOnlyList<M.Migration> GetMigrations(string path)
87+
private IReadOnlyList<M.Migration> GetMigrations(string path)
8888
{
89+
path = this.GetFullPath(path);
90+
8991
return M.MigrationDiscoverer.GetAll(path);
9092
}
9193

PSql.Deploy/Commands/InvokeSqlMigrationsCommand.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,12 @@ protected override void BeginProcessing()
7777
{
7878
base.BeginProcessing();
7979

80-
var currentPath = this.GetCurrentPath();
81-
8280
_session = new(
8381
GetOptions(),
84-
new CmdletMigrationConsole(this, currentPath)
82+
new CmdletMigrationConsole(this, this.GetCurrentPath())
8583
);
8684

87-
_session.DiscoverMigrations(Path ?? currentPath, MaximumMigrationName);
85+
_session.DiscoverMigrations(this.GetFullPath(Path), MaximumMigrationName);
8886
}
8987

9088
/// <inheritdoc/>

PSql.Deploy/Commands/InvokeSqlSeedCommand.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,12 @@ protected override void BeginProcessing()
7070

7171
base.BeginProcessing();
7272

73-
var currentPath = this.GetCurrentPath();
74-
7573
_session = new(
7674
GetOptions(),
77-
new CmdletSeedConsole(this, currentPath)
75+
new CmdletSeedConsole(this, this.GetCurrentPath())
7876
);
7977

80-
_session.DiscoverSeeds(Path ?? currentPath, Seed);
78+
_session.DiscoverSeeds(this.GetFullPath(Path), Seed);
8179
}
8280

8381
protected override void ProcessRecord()

PSql.Deploy/Utilities/CmdletExtensions.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)