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

Force the display of a command's help text from ExecuteAsync? #48

Closed
domn1995 opened this issue Apr 12, 2020 · 5 comments · Fixed by #49
Closed

Force the display of a command's help text from ExecuteAsync? #48

domn1995 opened this issue Apr 12, 2020 · 5 comments · Fixed by #49
Labels
enhancement New feature or request

Comments

@domn1995
Copy link
Contributor

First of all, I love project! Here's the use case I'm trying figure out:

I have a pretty nested CLI app where some commands don't actually do anything, but rather just help organize the app. Example:

myapp
|_ sub1
   |_ sub-sub1

In this example, command sub1 doesn't do anything except organize the structure of the commands. As such, in the ICommand.ExecuteAsync(IConsole) implementation, I'm simply returning default. When running the app in the following manner myapp sub, it simply executes then exits without doing anything. My intended behavior, however, is for it to print its help text instead.

Is it possible to do this currently? Or is there a better way to implement this pattern?

Thanks, and again, I love the library!!! And I hope you enjoy the three coffees I bought you @Tyrrrz :)

@Tyrrrz
Copy link
Owner

Tyrrrz commented Apr 13, 2020

Hey, thanks a lot! Glad you're enjoying it.

It's currently not possible to trigger help manually, although I have an idea how to implement it.

To understand your scenario a bit better, is your code available on GitHub or somewhere else I could take a look at? Or maybe you can give me a more applied example which involves real command names, etc?

@domn1995
Copy link
Contributor Author

domn1995 commented Apr 14, 2020

Here's a really simple example repo I created:
https://github.com/domn1995/HelpTextExample

Current output

>app command1
>
>app command1 sub1
Doing work...

As you can see, the output of the first command is blank. I would like to show the help text there instead.

Desired output

>app command1
Usage
  app command1 [command]

Options
  -h|--help         Shows help text.

Commands
  sub1

You can run `app command1 [command] --help` to show help on a specific command.
>app command1 sub1
Doing work...

Essentially, since command1 doesn't actually do any work, it just "organizes" the command line structure, I would like to show its help text when no arguments are given to make it clear to the user that this command doesn't really do anything.

If this is a feature that you believe would benefit the project, I would love to submit a PR. Just point me in the right direction.

Cheers!

@Tyrrrz
Copy link
Owner

Tyrrrz commented Apr 14, 2020

My first idea is to extend the CommandException with an extra parameter ShowHelp, which would get inspected by CliApplication. Then you would be able to do:

[Command("docker container")]
public class ContainerCommand : ICommand
{
    public ValueTask ExecuteAsync(IConsole consonle) =>
        throw new CommandException("Please specify a command.", showHelp: true);
}

@domn1995
Copy link
Contributor Author

domn1995 commented Apr 14, 2020

I like it. Do you want me to create a new issue for the feature and submit a PR?

@Tyrrrz
Copy link
Owner

Tyrrrz commented Apr 14, 2020

Sure, go ahead.

@Tyrrrz Tyrrrz changed the title Question: How to force the display of a command's help text from ExecuteAsync? Force the display of a command's help text from ExecuteAsync? Apr 14, 2020
@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants