Skip to content

Commit 1f6fc19

Browse files
edvilmedsplaisted
authored andcommitted
Simplify code and translations
1 parent 623d36a commit 1f6fc19

16 files changed

+78
-21
lines changed

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2479,4 +2479,7 @@ To display a value, specify the corresponding command-line option without provid
24792479
<data name="ToolRunFromSourceOptionDescription" xml:space="preserve">
24802480
<value>Executes a tool from source without permanently installing it. </value>
24812481
</data>
2482-
</root>
2482+
<data name="ToolRunFromSourceUserConfirmationPrompt" xml:space="preserve">
2483+
<value>Tool not found in the system. Do you want to run it from source? [y/n] </value>
2484+
</data>
2485+
</root>

src/Cli/dotnet/Commands/Tool/Run/ToolRunCommandParser.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal static class ToolRunCommandParser
4040

4141
public static readonly Option<string[]> FromSourceAddSourceOption = ToolInstallCommandParser.AddSourceOption;
4242

43-
public static readonly Option<VerbosityOptions> VerbosityOption = CommonOptions.VerbosityOption;
43+
public static readonly Option<VerbosityOptions> FromSourceVerbosityOption = CommonOptions.VerbosityOption;
4444

4545
private static readonly Command Command = ConstructCommand();
4646

@@ -56,11 +56,12 @@ private static Command ConstructCommand()
5656
command.Arguments.Add(CommandNameArgument);
5757
command.Arguments.Add(CommandArgument);
5858
command.Options.Add(RollForwardOption);
59+
5960
command.Options.Add(FromSourceOption);
6061
command.Options.Add(FromSourceConfigFile);
6162
command.Options.Add(FromSourceSourceOption);
6263
command.Options.Add(FromSourceAddSourceOption);
63-
command.Options.Add(VerbosityOption);
64+
command.Options.Add(FromSourceVerbosityOption);
6465

6566
command.Options.Add(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption);
6667
command.Options.Add(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption);

src/Cli/dotnet/Commands/Tool/Run/ToolRunFromSourceCommand.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@
55
using Microsoft.DotNet.Cli.CommandFactory;
66
using Microsoft.DotNet.Cli.CommandFactory.CommandResolution;
77
using Microsoft.DotNet.Cli.Commands.Tool.Install;
8-
using Microsoft.DotNet.Cli.ToolManifest;
98
using Microsoft.DotNet.Cli.ToolPackage;
10-
using Microsoft.DotNet.Cli.Utils;
11-
using Microsoft.DotNet.Cli.Utils.Extensions;
12-
using Microsoft.Extensions.EnvironmentAbstractions;
13-
using NuGet.Frameworks;
14-
using NuGet.Packaging;
159
using NuGet.Versioning;
1610

1711
namespace Microsoft.DotNet.Cli.Commands.Tool.Run
1812
{
19-
internal class ToolRunFromSourceCommand(
20-
ParseResult result) : CommandBase(result)
13+
internal class ToolRunFromSourceCommand(ParseResult result) : CommandBase(result)
2114
{
2215
private readonly string? _toolCommandName = result.GetValue(ToolRunCommandParser.CommandNameArgument);
2316
private readonly IEnumerable<string>? _forwardArguments = result.GetValue(ToolRunCommandParser.CommandArgument);
@@ -27,11 +20,11 @@ internal class ToolRunFromSourceCommand(
2720
private readonly string[] _addSource = result.GetValue(ToolRunCommandParser.FromSourceAddSourceOption) ?? [];
2821
private readonly bool _ignoreFailedSources = result.GetValue(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption);
2922
private readonly bool _interactive = result.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption);
30-
private readonly VerbosityOptions _verbosity = result.GetValue(ToolRunCommandParser.VerbosityOption);
23+
private readonly VerbosityOptions _verbosity = result.GetValue(ToolRunCommandParser.FromSourceVerbosityOption);
3124

3225
public override int Execute()
3326
{
34-
if (!UserAgreedToExecuteFromSource())
27+
if (!UserAgreedToRunFromSource())
3528
{
3629
return 1;
3730
}
@@ -46,17 +39,12 @@ public override int Execute()
4639

4740
string tempDirectory = PathUtilities.CreateTempSubdirectory();
4841

49-
ToolManifestFinder toolManifestFinder = new ToolManifestFinder(new(tempDirectory));
50-
ToolManifestEditor toolManifestEditor = new ToolManifestEditor();
51-
FilePath toolManifestPath = toolManifestFinder.FindFirst(true);
52-
5342
ToolPackageStoreAndQuery toolPackageStoreAndQuery = new(new(tempDirectory));
5443
ToolPackageDownloader toolPackageDownloader = new(toolPackageStoreAndQuery);
5544

5645
IToolPackage toolPackage = toolPackageDownloader.InstallPackage(
5746
new PackageLocation(
58-
nugetConfig: _configFile != null ? new FilePath(_configFile) : null,
59-
rootConfigDirectory: toolManifestPath.GetDirectoryPath().GetParentPath(),
47+
nugetConfig: _configFile != null ? new(_configFile) : null,
6048
sourceFeedOverrides: _sources,
6149
additionalFeeds: _addSource),
6250
packageId: packageId,
@@ -73,10 +61,10 @@ public override int Execute()
7361
return result.ExitCode;
7462
}
7563

76-
private bool UserAgreedToExecuteFromSource()
64+
private bool UserAgreedToRunFromSource()
7765
{
7866
// TODO: Use a better way to ask for user input
79-
Console.Write("Tool will be run from source. Accept? [y]".Red());
67+
Console.Write(CliCommandStrings.ToolRunFromSourceUserConfirmationPrompt);
8068
bool userAccepted = Console.ReadKey().Key == ConsoleKey.Y;
8169
Console.WriteLine();
8270
return userAccepted;

src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)