Skip to content

Commit e07a46b

Browse files
edvilmedsplaisted
authored andcommitted
Add version option
1 parent 5ccd294 commit e07a46b

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal class ToolExecuteCommand(ParseResult result) : CommandBase(result)
2323
private readonly bool _interactive = result.GetValue(ToolExecuteCommandParser.InteractiveOption);
2424
private readonly VerbosityOptions _verbosity = result.GetValue(ToolExecuteCommandParser.VerbosityOption);
2525
private readonly bool _yes = result.GetValue(ToolExecuteCommandParser.YesOption);
26+
private readonly bool _prerelease = result.GetValue(ToolExecuteCommandParser.PrereleaseOption);
2627

2728
public override int Execute()
2829
{

src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommandParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal static class ToolExecuteCommandParser
2020
Description = "arguments forwarded to the tool"
2121
};
2222

23+
public static readonly Option<string> VersionOption = ToolInstallCommandParser.VersionOption;
2324
public static readonly Option<bool> RollForwardOption = ToolInstallCommandParser.RollForwardOption;
2425
public static readonly Option<bool> PrereleaseOption = ToolInstallCommandParser.PrereleaseOption;
2526
public static readonly Option<string> ConfigOption = ToolInstallCommandParser.ConfigOption;
@@ -46,6 +47,7 @@ private static Command ConstructCommand()
4647
command.Arguments.Add(PackageIdentityArgument);
4748
command.Arguments.Add(CommandArgument);
4849

50+
command.Options.Add(VersionOption);
4951
command.Options.Add(RollForwardOption);
5052
command.Options.Add(PrereleaseOption);
5153
command.Options.Add(ConfigOption);

src/Cli/dotnet/Commands/Tool/Install/ParseResultExtension.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ internal static class ParseResultExtension
1313
{
1414
public static VersionRange GetVersionRange(this ParseResult parseResult)
1515
{
16-
string packageVersion =
17-
parseResult.GetValue(CommonArguments.PackageIdentityArgument(false))?.Version?.ToString() ??
18-
parseResult.GetValue(CommonArguments.PackageIdentityArgument(true))?.Version?.ToString() ??
19-
parseResult.GetValue(ToolInstallCommandParser.VersionOption);
16+
var packageVersionFromIdentityArgument = parseResult.GetValue(ToolInstallCommandParser.PackageIdentityArgument)?.Version?.ToString();
17+
var packageVersionFromVersionOption = parseResult.GetValue(ToolInstallCommandParser.VersionOption);
18+
19+
// Check that only one of these has a value
20+
if (!string.IsNullOrEmpty(packageVersionFromIdentityArgument) && !string.IsNullOrEmpty(packageVersionFromVersionOption))
21+
{
22+
throw new GracefulException(CliStrings.PackageIdentityArgumentVersionOptionConflict);
23+
}
24+
25+
string packageVersion = packageVersionFromIdentityArgument ?? packageVersionFromVersionOption;
2026

2127
bool prerelease = parseResult.GetValue(ToolInstallCommandParser.PrereleaseOption);
2228

src/Cli/dotnet/Commands/Tool/Install/ToolInstallCommand.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ internal class ToolInstallCommand(
2121
private readonly string _framework = parseResult.GetValue(ToolInstallCommandParser.FrameworkOption);
2222

2323

24-
internal static void EnsureNoConflictPackageIdentityVersionOption(ParseResult parseResult)
25-
{
26-
if (!string.IsNullOrEmpty(parseResult.GetValue(ToolInstallCommandParser.PackageIdentityArgument)?.Version?.ToString()) &&
27-
!string.IsNullOrEmpty(parseResult.GetValue(ToolInstallCommandParser.VersionOption)))
28-
{
29-
throw new GracefulException(CliStrings.PackageIdentityArgumentVersionOptionConflict);
30-
}
31-
}
32-
3324
public override int Execute()
3425
{
3526
ToolAppliedOption.EnsureNoConflictGlobalLocalToolPathOption(
@@ -39,8 +30,6 @@ public override int Execute()
3930
ToolAppliedOption.EnsureToolManifestAndOnlyLocalFlagCombination(
4031
_parseResult);
4132

42-
EnsureNoConflictPackageIdentityVersionOption(_parseResult);
43-
4433
if (_global || !string.IsNullOrWhiteSpace(_toolPath))
4534
{
4635
return (_toolInstallGlobalOrToolPathCommand ?? new ToolInstallGlobalOrToolPathCommand(_parseResult)).Execute();

test/dotnet.Tests/CompletionTests/snapshots/bash/DotnetCliSnapshotTests.VerifyCompletions.verified.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ _testhost_tool_execute() {
17921792
prev="${COMP_WORDS[COMP_CWORD-1]}"
17931793
COMPREPLY=()
17941794

1795-
opts="--allow-roll-forward --prerelease --configfile --source --add-source --ignore-failed-sources --interactive --yes --verbosity --help"
1795+
opts="--version --allow-roll-forward --prerelease --configfile --source --add-source --ignore-failed-sources --interactive --yes --verbosity --help"
17961796
opts="$opts $(${COMP_WORDS[0]} complete --position ${COMP_POINT} ${COMP_LINE} 2>/dev/null | tr '\n' ' ')"
17971797

17981798
if [[ $COMP_CWORD == "$1" ]]; then

test/dotnet.Tests/CompletionTests/snapshots/pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,7 @@ Register-ArgumentCompleter -Native -CommandName 'testhost' -ScriptBlock {
10961096
}
10971097
'testhost;tool;execute' {
10981098
$staticCompletions = @(
1099+
[CompletionResult]::new('--version', '--version', [CompletionResultType]::ParameterName, "The version of the tool package to install.")
10991100
[CompletionResult]::new('--allow-roll-forward', '--allow-roll-forward', [CompletionResultType]::ParameterName, "Allow a .NET tool to roll forward to newer versions of the .NET runtime if the runtime it targets isn`'t installed.")
11001101
[CompletionResult]::new('--prerelease', '--prerelease', [CompletionResultType]::ParameterName, "Include pre-release packages.")
11011102
[CompletionResult]::new('--configfile', '--configfile', [CompletionResultType]::ParameterName, "The NuGet configuration file to use.")

test/dotnet.Tests/CompletionTests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ _testhost() {
11611161
;;
11621162
(execute)
11631163
_arguments "${_arguments_options[@]}" : \
1164+
'--version=[The version of the tool package to install.]:VERSION: ' \
11641165
'--allow-roll-forward[Allow a .NET tool to roll forward to newer versions of the .NET runtime if the runtime it targets isn'\''t installed.]' \
11651166
'--prerelease[Include pre-release packages.]' \
11661167
'--configfile=[The NuGet configuration file to use.]:FILE: ' \

0 commit comments

Comments
 (0)