-
Notifications
You must be signed in to change notification settings - Fork 1.1k
sln-list: Add format options #47618
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
base: main
Are you sure you want to change the base?
sln-list: Add format options #47618
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request introduces a new output format option for the "dotnet sln list" command to improve parseability for tools. Key changes include:
- Adding the SlnListOutputFormat enum with Text, Raw, and Json options.
- Updating the command parser and help text to incorporate the new --format option.
- Modifying the list project execution to output data in the selected format.
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Cli/dotnet/commands/dotnet-sln/list/SlnListOutputFormat.cs | Adds a new enum for output formats. |
src/Cli/dotnet/commands/dotnet-sln/list/SlnListParser.cs | Introduces and adds the new --format CLI option. |
test/dotnet-sln.Tests/GivenDotnetSlnList.cs | Updates help text to include the --format option details. |
src/Cli/dotnet/commands/dotnet-sln/list/Program.cs | Implements format-specific output behavior and adjusts project file retrieval. |
Comments suppressed due to low confidence (2)
src/Cli/dotnet/commands/dotnet-sln/list/Program.cs:30
- The removal of the 'includeSolutionFilterFiles: true' parameter may alter solution file detection behavior. Please verify that this change is intentional and update unit tests if needed.
string solutionFileFullPath = SlnFileFactory.GetSolutionFileFullPath(_fileOrDirectory);
src/Cli/dotnet/commands/dotnet-sln/list/Program.cs:52
- When no projects are found, outputting a plain text message may be inconsistent with the JSON output format. Consider outputting an empty JSON array ("[]") when the --format option is set to Json.
return;
using Microsoft.DotNet.Cli; | ||
using Microsoft.DotNet.Cli.Utils; | ||
|
||
namespace Microsoft.DotNet.Cli; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully this avoids conflicts with the current namespaces efforts ;)
|
||
public enum SlnListOutputFormat | ||
{ | ||
Text, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be renamed Table
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No preference from me
@@ -19,8 +19,9 @@ dotnet solution <SLN_FILE> list [options] | |||
<SLN_FILE> The solution file to operate on. If not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}] | |||
|
|||
Options: | |||
--solution-folders Display solution folder paths. | |||
-?, -h, --help Show command line help."; | |||
--solution-folders Display solution folder paths. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: sort?
|
||
public enum SlnListOutputFormat | ||
{ | ||
Text, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No preference from me
@@ -27,6 +32,7 @@ private static CliCommand ConstructCommand() | |||
CliCommand command = new("list", LocalizableStrings.ListAppFullName); | |||
|
|||
command.Options.Add(SolutionFolderOption); | |||
command.Options.Add(OutputFormatOption); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the user passes in something invalid? And is this case-sensitive or insensitive?
} | ||
|
||
public override int Execute() | ||
{ | ||
string solutionFileFullPath = SlnFileFactory.GetSolutionFileFullPath(_fileOrDirectory, includeSolutionFilterFiles: true); | ||
string solutionFileFullPath = SlnFileFactory.GetSolutionFileFullPath(_fileOrDirectory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
.ToArray(); | ||
} | ||
string[] paths = _displaySolutionFolders | ||
? solution.SolutionFolders.Select(folder => Path.GetDirectoryName(folder.Path.TrimStart('/'))).ToArray() // VS-SolutionPersistence does not return a path object, so there might be issues with forward/backward slashes on different platforms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? solution.SolutionFolders.Select(folder => Path.GetDirectoryName(folder.Path.TrimStart('/'))).ToArray() // VS-SolutionPersistence does not return a path object, so there might be issues with forward/backward slashes on different platforms | |
// VS-SolutionPersistence does not return a path object, so there might be issues with forward/backward slashes on different platforms | |
? solution.SolutionFolders.Select(folder => Path.GetDirectoryName(folder.Path.TrimStart('/'))).ToArray() |
case SlnListOutputFormat.Json: | ||
Reporter.Output.WriteLine(JsonSerializer.Serialize(paths)); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default? Same as Text, right?
The current output for
dotnet sln list
might not be easily parseable by other programs.This adds the
--format
option (following other commands on the cli) with values:text
(Default): Displays a header and a list of projects/folders.raw
: Displays no header and a list of projects/folders. This can be useful for piping to other commands.json
: Displays a json array with the projects/folders.