Skip to content

Commit

Permalink
Change to make "solution" the primary command for SlnCommand and "sln…
Browse files Browse the repository at this point in the history
…" to a shorthand alias.

Additional changes have been made to tests that relied on certain outputs using "sln" and hard-baked calls to "sln" from internal code.
  • Loading branch information
SourceCodeWhen committed Sep 20, 2024
1 parent cf81c08 commit 8ea8db8
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/BuiltInTools/dotnet-watch/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal sealed class CommandLineOptions
"restore",
"run",
"sdk",
"sln",
"solution",
"store",
"test",
"tool",
Expand Down Expand Up @@ -179,7 +179,7 @@ internal sealed class CommandLineOptions
BuildProperties = ParseBuildProperties(parseResult.GetValue(propertyOption) ?? []).ToArray(),
};

// Parses name=value pairs passed to --property. Skips invalid input.
// Parses name=value pairs passed to --property. Skips invalid input.
// We don't report error here as it will be reported by dotnet run.
static IEnumerable<(string key, string value)> ParseBuildProperties(string[] properties)
=> from property in properties
Expand Down Expand Up @@ -240,7 +240,7 @@ private static IReadOnlyList<string> GetCommandArguments(
{
explicitCommand = token;
}
else
else
{
if (!dashDashInserted && i >= unmatchedTokensBeforeDashDash)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet-new3/Dotnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal static Dotnet AddProjectsToSolution(string solutionFile, IReadOnlyList<
{
List<string> allArgs = new()
{
"sln",
"solution",
solutionFile,
"add"
};
Expand Down
10 changes: 5 additions & 5 deletions src/Cli/dotnet/ReleasePropertyProjectLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public IEnumerable<string> GetCustomDefaultConfigurationValueIfSpecified()
}
}
}
return null; // If nothing can be found: that's caught by MSBuild XMake::ProcessProjectSwitch -- don't change the behavior by failing here.
return null; // If nothing can be found: that's caught by MSBuild XMake::ProcessProjectSwitch -- don't change the behavior by failing here.
}

/// <returns>An arbitrary existant project in a solution file. Returns null if no projects exist.
Expand Down Expand Up @@ -205,7 +205,7 @@ public IEnumerable<string> GetCustomDefaultConfigurationValueIfSpecified()
/// <summary>
/// Returns an arbitrary project for the solution. Relies on the .NET SDK PrepareForPublish or _VerifyPackReleaseConfigurations MSBuild targets to catch conflicting values of a given property, like PublishRelease or PackRelease.
/// </summary>
/// <param name="sln">The solution to get an arbitrary project from.</param>
/// <param name="solution">The solution to get an arbitrary project from.</param>
/// <param name="globalProps">The global properties to load into the project.</param>
/// <returns>null if no project exists in the solution that can be evaluated properly. Else, the first project in the solution that can be.</returns>
private ProjectInstance? GetSingleProjectFromSolution(SlnFile sln, Dictionary<string, string> globalProps)
Expand Down Expand Up @@ -253,13 +253,13 @@ private bool IsUnanalyzableProjectInSolution(SlnProject project, string projectF
return null;
}

/// <returns>Returns true if the path exists and is a project file type.</returns>
/// <returns>Returns true if the path exists and is a project file type.</returns>
private bool IsValidProjectFilePath(string path)
{
return File.Exists(path) && Path.GetExtension(path).EndsWith("proj");
}

/// <returns>Returns true if the path exists and is a sln file type.</returns>
/// <returns>Returns true if the path exists and is a sln file type.</returns>
private bool IsValidSlnFilePath(string path)
{
return File.Exists(path) && Path.GetExtension(path).EndsWith("sln");
Expand All @@ -271,7 +271,7 @@ private Dictionary<string, string> GetUserSpecifiedExplicitMSBuildProperties()
Dictionary<string, string> globalProperties = new(StringComparer.OrdinalIgnoreCase);

string[]? globalPropEnumerable = _parseResult.GetValue(CommonOptions.PropertiesOption);

if ( globalPropEnumerable != null )
{
foreach (var keyEqValString in globalPropEnumerable)
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Telemetry/TelemetryFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public IEnumerable<ApplicationInsightsEntryFormat> Filter(object objectToFilter)
private static List<IParseResultLogRule> ParseResultLogRules => new()
{
new AllowListToSendFirstArgument(new HashSet<string> {"new", "help"}),
new AllowListToSendFirstAppliedOptions(new HashSet<string> {"add", "remove", "list", "sln", "nuget"}),
new AllowListToSendFirstAppliedOptions(new HashSet<string> {"add", "remove", "list", "solution", "nuget"}),
new TopLevelCommandNameAndOptionToLog
(
topLevelCommandName: new HashSet<string> {"build", "publish"},
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/commands/dotnet-help/HelpUsageText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal static class HelpUsageText
restore {LocalizableStrings.RestoreDefinition}
run {LocalizableStrings.RunDefinition}
sdk {LocalizableStrings.SdkDefinition}
sln {LocalizableStrings.SlnDefinition}
solution {LocalizableStrings.SlnDefinition}
store {LocalizableStrings.StoreDefinition}
test {LocalizableStrings.TestDefinition}
tool {LocalizableStrings.ToolDefinition}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal static bool AddProjectsToSolution(string solutionPath, IReadOnlyList<st
{
PathUtility.EnsureAllPathsExist(new[] { solutionPath }, CommonLocalizableStrings.FileNotFound, allowDirectories: false);
PathUtility.EnsureAllPathsExist(projectsToAdd, CommonLocalizableStrings.FileNotFound, allowDirectories: false);
IEnumerable<string> commandArgs = new[] { "sln", solutionPath, "add" }.Concat(projectsToAdd);
IEnumerable<string> commandArgs = new[] { "solution", solutionPath, "add" }.Concat(projectsToAdd);
if (!string.IsNullOrWhiteSpace(solutionFolder))
{
commandArgs = commandArgs.Append(SlnAddParser.SolutionFolderOption.Name).Append(solutionFolder);
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/commands/dotnet-sln/SlnArgumentValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void ParseAndValidateArguments(string _fileOrDirectory, IReadOnlyC
{
string.Format(CommonLocalizableStrings.SolutionArgumentMisplaced, slnFile),
CommonLocalizableStrings.DidYouMean,
$" dotnet sln {slnFile} {command} {args}{projectArgs}"
$" dotnet solution {slnFile} {command} {args}{projectArgs}"
});
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using NuGet.Packaging;
using LocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings;

namespace Microsoft.DotNet.Cli
Expand All @@ -10,6 +11,8 @@ internal static class SlnCommandParser
{
public static readonly string DocsLink = "https://aka.ms/dotnet-sln";

public static readonly string CommandName = "solution";
public static readonly string[] CommandAliases = ["sln"];
public static readonly CliArgument<string> SlnArgument = new CliArgument<string>(LocalizableStrings.SolutionArgumentName)
{
HelpName = LocalizableStrings.SolutionArgumentName,
Expand All @@ -26,7 +29,12 @@ public static CliCommand GetCommand()

private static CliCommand ConstructCommand()
{
DocumentedCommand command = new("sln", DocsLink, LocalizableStrings.AppFullName);
DocumentedCommand command = new(CommandName, DocsLink, LocalizableStrings.AppFullName);

for (int i = 0; i < CommandAliases.Length; i++)
{
command.Aliases.Add(CommandAliases[i]);
}

command.Arguments.Add(SlnArgument);
command.Subcommands.Add(SlnAddParser.GetCommand());
Expand Down
4 changes: 2 additions & 2 deletions test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GivenDotnetSlnAdd : SdkTest
Add one or more projects to a solution file.
Usage:
dotnet sln <SLN_FILE> add [<PROJECT_PATH>...] [options]
dotnet solution <SLN_FILE> add [<PROJECT_PATH>...] [options]
Arguments:
<SLN_FILE> The solution file to operate on. If not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}]
Expand Down Expand Up @@ -1347,7 +1347,7 @@ private void VerifySuggestionAndUsage(string arguments)
cmd.StdErr.Should().BeVisuallyEquivalentTo(
string.Format(CommonLocalizableStrings.SolutionArgumentMisplaced, "App.sln") + Environment.NewLine
+ CommonLocalizableStrings.DidYouMean + Environment.NewLine
+ $" dotnet sln App.sln add {arguments} Lib {projectArg}"
+ $" dotnet solution App.sln add {arguments} Lib {projectArg}"
);
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized("");
}
Expand Down
2 changes: 1 addition & 1 deletion test/dotnet-sln.Tests/GivenDotnetSlnList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GivenDotnetSlnList : SdkTest
List all projects in a solution file.
Usage:
dotnet sln <SLN_FILE> list [options]
dotnet solution <SLN_FILE> list [options]
Arguments:
<SLN_FILE> The solution file to operate on. If not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}]
Expand Down
4 changes: 2 additions & 2 deletions test/dotnet-sln.Tests/GivenDotnetSlnRemove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GivenDotnetSlnRemove : SdkTest
Remove one or more projects from a solution file.
Usage:
dotnet sln <SLN_FILE> remove [<PROJECT_PATH>...] [options]
dotnet solution <SLN_FILE> remove [<PROJECT_PATH>...] [options]
Arguments:
<SLN_FILE> The solution file to operate on. If not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}]
Expand Down Expand Up @@ -744,7 +744,7 @@ public void WhenSolutionIsPassedAsProjectItPrintsSuggestionAndUsage()
cmd.StdErr.Should().BeVisuallyEquivalentTo(
string.Format(CommonLocalizableStrings.SolutionArgumentMisplaced, "App.sln") + Environment.NewLine
+ CommonLocalizableStrings.DidYouMean + Environment.NewLine
+ $" dotnet sln App.sln remove {projectArg}"
+ $" dotnet solution App.sln remove {projectArg}"
);
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized("");
}
Expand Down

0 comments on commit 8ea8db8

Please sign in to comment.