Skip to content

Commit 167e191

Browse files
committed
Add option to skip reverting consumer package version in "dibix artifact reset" CLI command
1 parent 06cb290 commit 167e191

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/Dibix.Sdk.Cli/Commands/Artifact/ResetNuGetPackagesCommand.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ namespace Dibix.Sdk.Cli
77
{
88
internal sealed class ResetNuGetPackagesCommand : ConsumerPackageCommand
99
{
10+
private readonly Option<bool> _revertConsumerPackageVersionOption;
11+
1012
protected override string PackageNameArgumentDescription => "The name of the package to reset. If not specified, all packages will be reset.";
1113

1214
public ResetNuGetPackagesCommand(EnvironmentVariableOption consumerDirectoryOption) : base("reset", "Removes the current version of the Dibix packages from the local NuGet package cache and reverts the consumer to the previous version.", consumerDirectoryOption)
1315
{
16+
_revertConsumerPackageVersionOption = new Option<bool>("--revert-consumer-package-version", "-r")
17+
{
18+
Description = "Revert the consumer package version to the previous version.",
19+
DefaultValueFactory = _ => true
20+
};
21+
22+
Add(_revertConsumerPackageVersionOption);
1423
}
1524

1625
protected override async Task<int> Execute(ParseResult parseResult, CancellationToken cancellationToken)
@@ -21,6 +30,7 @@ protected override async Task<int> Execute(ParseResult parseResult, Cancellation
2130
ConsoleUtility.WriteLineInformation(PackageName == null ? "Resetting all packages.." : $"Resetting only package '{PackageName}'");
2231

2332
string[] packagesToReset = PackageName != null ? [PackageName] : ArtifactUtility.NuGetPackageNames;
33+
bool revertConsumerPackageVersion = parseResult.GetRequiredValue<bool>(_revertConsumerPackageVersionOption);
2434

2535
foreach (string packageName in packagesToReset)
2636
{
@@ -29,8 +39,11 @@ protected override async Task<int> Execute(ParseResult parseResult, Cancellation
2939
ConsoleUtility.WriteLineDebug($"Removing package '{packageName}' version '{packageVersion}' from local NuGet package cache");
3040
ArtifactUtility.RemovePackageFromNuGetPackageCache(packageName, packageVersion);
3141

32-
ConsoleUtility.WriteLineDebug($"Reverting consumer package reference of package '{packageName}'");
33-
await ConsumerPackageManager.RevertPackageVersionChanges(packageName, ArtifactUtility.IsSdk(packageName), cancellationToken).ConfigureAwait(false);
42+
if (revertConsumerPackageVersion)
43+
{
44+
ConsoleUtility.WriteLineDebug($"Reverting consumer package reference of package '{packageName}'");
45+
await ConsumerPackageManager.RevertPackageVersionChanges(packageName, ArtifactUtility.IsSdk(packageName), cancellationToken).ConfigureAwait(false);
46+
}
3447
}
3548

3649
return 0;

0 commit comments

Comments
 (0)