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

How can you populate multi command help #42

Open
lwdye opened this issue Sep 21, 2017 · 5 comments
Open

How can you populate multi command help #42

lwdye opened this issue Sep 21, 2017 · 5 comments

Comments

@lwdye
Copy link

lwdye commented Sep 21, 2017

How can you set help strings for commands? I'm able to generate help for individual flags but not for the commands themselves. Suppose we have

data Commands = Hello{myflag::String <?> "it works!"} | Goodbye deriving (Show, Generic)

How can one generate the help "Print greeting" and "Say goodbye" for hello and goodbye as below. The mechanism is available in the underlying Options.Applicative.

Usage: commands COMMAND

Available options:
  -h,--help                Show this help text

Available commands:
  hello                    Print greeting
  goodbye                  Say goodbye
@Gabriella439
Copy link
Owner

I don't think there is a good way to do this within this library's framework

@lwdye
Copy link
Author

lwdye commented Sep 22, 2017

Thank you. Yes, I was also stuck seeing how to do this cleanly. One idea is to "somehow" use the type specification to generate unique tags / enums / strings as keys to hash table, map, JSON etc

type magic....

....toList [("Commands.Hello","Print greeting"),
                ("Commands.Goodbye","Say goodbye"),
                ("Commands.Hello.myflag", "it works!)]

I like this in that it would use your elegant type-level design but separate the "help data". Thoughts?

@lwdye
Copy link
Author

lwdye commented Sep 22, 2017

As a workaround I can specify the program description as follows

let infomods = briefDesc <> fullDesc <> header ("myprogram - acme missile control")
                              <> footer API.copyright <> progDescDoc (Just API.progDescDoc)
let prefsmods = showHelpOnEmpty <> showHelpOnError
command<- getRecordWith infomods prefsmods

If I could suppress "Available commands:" section. This would be sufficient. Also it is redundant as it stands now since

Usage: myprogram (create | update | send | missiles )
Available options:
  -h,--help                Show this help text
Available commands:
  create                                   
  update                   
  send                    
  missiles              

doesn't give any additional information. Perhaps just dropping "Available commands" is a good idea in any case or perhaps the case a program description is supplied with showHelpOnEmpty. Thoughts?

@lwdye
Copy link
Author

lwdye commented Sep 22, 2017

Related is that given -h is supported on

myprogram -h

how can we specify other flags at top level?

@Gabriella439
Copy link
Owner

So there actually is an intermediate solution in between optparse-applicative and optparse-generic, which is the TurtleOptions module:

https://hackage.haskell.org/package/turtle-1.4.3/docs/Turtle-Options.html

For example, it has a subcommandGroup function which is similar to what you just described:

https://hackage.haskell.org/package/turtle-1.4.3/docs/Turtle-Options.html#v:subcommandGroup

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