spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Function to render help text

Open WajahatAliAbid opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe. I was looking to find a way to show command help during execution of a command. For example, I have main command of cli set to display fidglet text. But I want to show command help right after.

Describe the solution you'd like Ideally, having a function in AnsiConsole or CommandContext to render command help. For example

public override int Execute(CommandContext context)
{
   AnsiConsole.WriteHelp();
}

I am not sure if there exists a function to provide such implementation. If there is, please refer me to that.

WajahatAliAbid avatar Jan 24 '22 21:01 WajahatAliAbid

Would be good to add a:

public override int Execute(CommandContext context)
{
   AnsiConsole.WriteVersion();
}

Simonl9l avatar Jan 31 '22 22:01 Simonl9l

Good question, is there a way to call the help? I use a default command and I would like to show the help there

rerasolutions avatar Feb 09 '22 08:02 rerasolutions

I need the same, a default command that shows a splash + displays help

digitaldias avatar Feb 26 '22 06:02 digitaldias

PR (https://github.com/spectreconsole/spectre.console/pull/1133) raised for this issue.

If you have time ahead of the review/merge, please checkout the proposed implementation and comment as to the suitability of it, see: https://github.com/spectreconsole/spectre.console/blob/1fba0f97178c5bcf07e0bc51681413a7df199a4f/test/Spectre.Console.Cli.Tests/Data/Commands/DefaultCommand.cs

FrankRay78 avatar Jan 13 '23 14:01 FrankRay78

I am starting a greenfield application and I just learned today about Spectre.Console & Spectre.Console.Cli. It sounded great so I decided to use it. Very shortly after starting I realized when errors occur (such as user input invalid command, input, etc.) the error is displayed very nicely, but the help is not rendered. I think it's very common (and in my case desirable) to show the help when the user messes up the input. So it should show the error, then immediately write out the help to describe how to use the command. With the current implementation I don't see a way to accomplish that and it looks like this issue targets the problem.

Unfortunately it appears this issue has been open a very long time and the pull request to resolve this has been open for a while as well. I was looking forward to using Spectre.Console.CLI but, unfortunately, I guess because of this issue I'll check if System.CommandLine will allow me to do this, and if so, I'll be switching to that framework instead.

FWIW: My use case is I would like to provide a custom exception handler. If the exception is due to a problem parsing the input, I would like to display the error and then write help to the console. To accomplish this, I would just need a way to access the help writer from within an exception handler.

CrossBound avatar Apr 10 '23 22:04 CrossBound

FYI: It appears System.CommandLine supports my use case by default with no extra configuration required.

CrossBound avatar Apr 10 '23 22:04 CrossBound

@CrossBound I prepared the pull request to help address the issue, it's just waiting for review and could have been expedited if asked. It's a shame you didn't stick around for longer so that we might have been able to accommodate your use case more fully, however thank you for leaving feedback. Needless to say this is not a commercially oriented project and yet the judicious time and effort, delays included in that, does mean the codebase is a very high quality. We'd welcome pull requests if you did want to contribute in the future.

FrankRay78 avatar Apr 11 '23 08:04 FrankRay78