Skip to content
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

Function to render help text #702

Closed
WajahatAliAbid opened this issue Jan 24, 2022 · 7 comments · Fixed by #1259
Closed

Function to render help text #702

WajahatAliAbid opened this issue Jan 24, 2022 · 7 comments · Fixed by #1259
Assignees
Labels
area-CLI Command-Line Interface feature

Comments

@WajahatAliAbid
Copy link

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.

@nils-a nils-a added the feature label Jan 24, 2022
@Simonl9l
Copy link

Would be good to add a:

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

@rerasolutions
Copy link

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

@digitaldias
Copy link

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

@FrankRay78
Copy link
Contributor

PR (#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

@CrossBound
Copy link

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
Copy link

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

@FrankRay78
Copy link
Contributor

@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 FrankRay78 added the area-CLI Command-Line Interface label May 13, 2023
@FrankRay78 FrankRay78 linked a pull request Jul 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CLI Command-Line Interface feature
Projects
Status: Done 🚀
7 participants