Skip to content

tool-update: add --prerelease-skip flag #47174

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

Draft
wants to merge 1 commit into
base: release/9.0.3xx
Choose a base branch
from
Draft
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
14 changes: 14 additions & 0 deletions src/Cli/dotnet/commands/dotnet-tool/common/ToolAppliedOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ internal class ToolAppliedOption
Description = UpdateToolsLocalizableStrings.UpdateAllOptionDescription
};

public static CliOption<bool> UpdateSkipPreReleaseOption = new("--prerelease-skip")
{
Description = "TODO: Update description"
};

public static readonly CliOption<string> VersionOption
= ToolInstallCommandParser.VersionOption
?? new("--version"); // Workaround for Mono runtime (https://github.com/dotnet/sdk/issues/41672)
Expand All @@ -34,6 +39,15 @@ public static readonly CliOption<string> VersionOption
Arity = ArgumentArity.ZeroOrOne
};

internal static void EnsureUpdateSkipPreReleaseOptionSetWithUpdateAllOption(ParseResult parseResult, string message)
{
if (parseResult.GetResult(UpdateSkipPreReleaseOption) is not null &&
parseResult.GetResult(UpdateAllOption) is null)
{
throw new GracefulException(message);
}
}

internal static void EnsureNoConflictGlobalLocalToolPathOption(
ParseResult parseResult,
string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ internal class ToolInstallGlobalOrToolPathCommand : CommandBase
private readonly bool _allowRollForward;
private readonly bool _allowPackageDowngrade;
private readonly bool _updateAll;
private readonly bool _updateSkipPreRelease;
private readonly string _currentWorkingDirectory;
private readonly bool? _verifySignatures;

Expand Down Expand Up @@ -102,6 +103,7 @@ public ToolInstallGlobalOrToolPathCommand(
_createToolPackageStoreDownloaderUninstaller = createToolPackageStoreDownloaderUninstaller ??
ToolPackageFactory.CreateToolPackageStoresAndDownloaderAndUninstaller;
_updateAll = parseResult.GetValue(ToolUpdateCommandParser.UpdateAllOption);
_updateSkipPreRelease = parseResult.GetValue(ToolUpdateCommandParser.UpdateSkipPreReleaseOption);

_reporter = (reporter ?? Reporter.Output);
}
Expand Down Expand Up @@ -162,8 +164,12 @@ private int ExecuteInstallCommand(PackageId packageId)

if (oldPackageNullable != null)
{
if (oldPackageNullable.Version.IsPrerelease && _updateSkipPreRelease)
{
_reporter.WriteLine("TODO: Skip pre-release version update");
return 0;
}
NuGetVersion nugetVersion = GetBestMatchNugetVersion(packageId, versionRange, toolPackageDownloader);

if (ToolVersionAlreadyInstalled(oldPackageNullable, nugetVersion))
{
_reporter.WriteLine(string.Format(LocalizableStrings.ToolAlreadyInstalled, oldPackageNullable.Id, oldPackageNullable.Version.ToNormalizedString()).Green());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public override int Execute()
_parseResult,
LocalizableStrings.UpdateToolCommandInvalidAllAndVersion);

ToolAppliedOption.EnsureUpdateSkipPreReleaseOptionSetWithUpdateAllOption(
_parseResult,
"TODO: Update message");

EnsureEitherUpdateAllOrUpdateOption(
_parseResult,
LocalizableStrings.UpdateToolCommandInvalidAllAndPackageId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal static class ToolUpdateCommandParser

public static readonly CliOption<bool> AllowPackageDowngradeOption = ToolInstallCommandParser.AllowPackageDowngradeOption;

public static readonly CliOption<bool> UpdateSkipPreReleaseOption = ToolAppliedOption.UpdateSkipPreReleaseOption;

private static readonly CliCommand Command = ConstructCommand();

public static CliCommand GetCommand()
Expand All @@ -37,6 +39,7 @@ private static CliCommand ConstructCommand()
ToolInstallCommandParser.AddCommandOptions(command);
command.Options.Add(AllowPackageDowngradeOption);
command.Options.Add(UpdateAllOption);
command.Options.Add(UpdateSkipPreReleaseOption);

command.SetAction((parseResult) => new ToolUpdateCommand(parseResult).Execute());

Expand Down
Loading