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

Showing help on empty with inline subcommands #450

Open
moll opened this issue Mar 29, 2022 · 6 comments
Open

Showing help on empty with inline subcommands #450

moll opened this issue Mar 29, 2022 · 6 comments

Comments

@moll
Copy link

moll commented Mar 29, 2022

Hey again!

Hope your spring is going swell.

Do you have some tips on how to achieve showing help-on-empty when subcommands and subparsers are involved? That is, given something that contains the following:

cmd = Opt.subparser $
  Opt.command "foo" $ Opt.info fooCommands $
  Opt.progDesc "Foo commands."

fooCommands = Opt.subparser $
  Opt.command "bar" $ Opt.info (pure 'x') $
  Opt.progDesc "Go to bar."

..I'm trying to achieve that invoking ./program foo would print out the help with its subcommands (bar) along with local and global options. This with Opt.prefBacktrack = Opt.SubparserInline.

Right now I'm seeing ./program showing the top level commands (foo), however ./program foo erring with:

Usage: program foo COMMAND
Missing: COMMAND

Thanks in advance!

@HuwCampbell
Copy link
Collaborator

HuwCampbell commented Mar 29, 2022

The prefs mod showHelpOnEmpty works with subparsers as well as the top level.

*Options.Applicative Opt> main = customExecParser (prefs (showHelpOnEmpty <> subparserInline)) (info cmd idm)
*Options.Applicative Opt> :main foo
Missing: COMMAND

Usage: <interactive> foo COMMAND

  Foo commands.

@moll
Copy link
Author

moll commented Mar 29, 2022

Hey. Thanks for the quick response! Apologies. I classified the problem inadequately, I now realize. You're right. Help-on-empty for the subcommand does indeed show the usage line referencing the subcommand and any global options. What it does not seem to show are the subcommands themselves.

That is, at the top level there's a grouping listing all next level commands:

Usage: program COMMAND

Available commands:
  foo Foo commands.

Now I was expecting and trying to get the subparser to behave similarly — show available commands next level down. In the example we're playing with here, that'd be:

Missing: COMMAND

Usage: program foo COMMAND
  Foo commands.

Available commands:
  bar Go to bar.

Thanks!

@HuwCampbell
Copy link
Collaborator

HuwCampbell commented Mar 30, 2022

Ahh I see now.

When subparser inline is on, the subcommand is just included as a component of the parent parser. The parent parser isn't at its start though, so the showHelpOnEmpty case isn't being activated.

Interesting little edge case there.

This should be fixable by included a bit more information in the result of searchArg and stepParser.

@HuwCampbell
Copy link
Collaborator

I have a fix and tests. The code is too ugly to push for now, but I'll see if I can get something acceptable next weekend.

@moll
Copy link
Author

moll commented May 15, 2022

Great. Thank you!

HuwCampbell added a commit that referenced this issue Nov 16, 2022
Use an RWST monad (don't actually need Reader) to keep track of
whether the state did change.
@moll
Copy link
Author

moll commented May 6, 2024

Hey again! Am I mistaken if I say the fix you did back in 2022 has never made it to master? Thanks!

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

No branches or pull requests

2 participants