Skip to content

stop using System.CommandLine types that won't be public anymore #5493

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik requested a review from a team as a code owner May 28, 2025 11:46
@@ -199,7 +199,7 @@ public string GetDetailedHelp(string commandName, IServiceProvider services, int
{
if (handler.IsCommandSupported(group.Parser, services))
{
return group.GetDetailedHelp(command, services, consoleWidth);
return group.GetDetailedHelp(command, services);
Copy link
Member Author

@adamsitnik adamsitnik May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not removed the int consoleWidth argument from the public method as I am not sure what public means in this context ( is it exposed as a library to external customers who would get build errors?)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving the consoleWidth parameter in the public function is ok for now. There are other references outside of this repo.

@adamsitnik adamsitnik force-pushed the sclHelpIsInternal branch from 089db72 to 53c7036 Compare May 28, 2025 11:56
{
StringWriter console = new();
CommandLineConfiguration configuration = new(command)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the consoleWidth parameter means that the command help doesn't get formatted for the console width anymore? Hopefully System.CommandLine isn't using Console.WIndowWidth directly because this code can get hosted in an environment that doesn't work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it is using Console.WindowWidth which doesn't work when SOS is hosted under windbg or lldb. The hosting infrastructure has a method to get the console width that is passed down to the CommandService.

Copy link
Member Author

@adamsitnik adamsitnik May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it is using Console.WindowWidth which doesn't work when SOS is hosted under windbg or lldb. The hosting infrastructure has a method to get the console width that is passed down to the CommandService.

Do you remember if it just throws for SOS? If so, would it be acceptable to just wrap the logic in System.CommandLine and use int.MaxValue when Console.Width throws?

The alternative would be to extend the public HelpAction (or HelpOption) class with a new public property that would allow the users to specify the width (cc @jonsequitur)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikem8361 Do what the width is used for in SOS when it is hosted under windbg/lldb? I am wondering if we could remove the width dependency and have fixed formatting when it is hosted.

Copy link

@mikem8361 mikem8361 May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that this new version of System.CommandLine now calls Console.WindowWidth and SOS can't do anything about it. I'm not sure the API would actually throw an exception under the native debuggers but it does NOT return the correct screen width.

It is System.CommandLine that formats the help text given the screen width. In the current version that SOS uses, SOS can pass the screen width to the System.CommandLine help formatting function but the new version uses Console.WindowWidth directly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative would be to extend the public HelpAction (or HelpOption) class with a new public property that would allow the users to specify the width (cc @jonsequitur)

These kinds of properties shouldn't be on HelpOption because it assumes that the associated action is going to do something with the console at all, and I don't think that's always true. It would be more appropriate on HelpAction, though more awkward to get to. But we should definitely preserve the ability for the formatting to work correctly when console output is redirected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants