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

Divide subparsers by propMetaVar in help #121

Closed
d12frosted opened this issue Jan 11, 2015 · 4 comments
Closed

Divide subparsers by propMetaVar in help #121

d12frosted opened this issue Jan 11, 2015 · 4 comments

Comments

@d12frosted
Copy link

Hey.

For example I have

progParser :: Parser Prog
progParser = 
  subparser $
  metavar "PROG" <>
  ...

cmdParser :: Parser Command
cmdParser = 
  subparser $
  metavar "CMD" <>
  ...

mainParser :: Parser (Prog, Command)
mainParser = (,) <$> progParser <*> cmdParser

opts :: ParserInfo Args
opts = info (helper <*> mainParser) idm

Which brings me to

> :set args --help
> execParser opts
Usage: <interactive> PROG CMD

Available options:
  -h,--help                Show this help text
  -c,--config FILE         Use configuration FILE instead of default one at
                           ~/.kitsunebook.cfg

Available commands:
  prog1                    Prog 1 description
  prog2                    Prog 2 description
  ..
  progn                    Prog n description
  cmd1                     Command 1 description
  cmd2                     Command 2 description
  ..
  cmdn                     Command n description

But I really would like to have the next help message:

Usage: <interactive> PROG CMD

Available options:
  -h,--help                Show this help text
  -c,--config FILE         Use configuration FILE instead of default one at
                           ~/.kitsunebook.cfg

Available PROGs (or progs):
  prog1                    Prog 1 description
  prog2                    Prog 2 description
  ..
  progn                    Prog n description

Available CMDs (or cmds):
  cmd1                     Command 1 description
  cmd2                     Command 2 description
  ..
  cmdn                     Command n description

I want this only for situation when I specify some custom metavars.

Is it possible out of box?

@joeyh
Copy link

joeyh commented Jul 9, 2015

FWIW, I have a similar wish for the list of subcommands. I have lots of subcommands, that naturally fall into different sets, and it'd be great if those sets could be displayed together.

@nomeata
Copy link

nomeata commented Dec 25, 2015

+1

@nomeata
Copy link

nomeata commented Dec 25, 2015

FWIW, I have a similar wish for the list of subcommands. I have lots of subcommands, that naturally fall into different sets, and it'd be great if those sets could be displayed together.

Here is a hack for that, producing this output:

Available commands:
  GME creation commands:   
  assemble                 creates a gme file from the given source

  OID code creation commands:

  oid-table                creates a PDF file with all codes in the yaml file
  oid-codes                creates PNG files for every OID in the yaml file.
  oid-code                 creates PNG files for each given code(s)

  GME analysis commands:   
  info                     Print general information about a GME file
  export                   dumps the file in the human-readable yaml format
  scripts                  prints the decoded scripts for each OID
  script                   prints the decoded scripts for a specific OID
  games                    prints the decoded games
  lint                     checks for errors in the file or in this program
  segments                 lists all known parts of the file, with description.
  segment                  prints the decoded scripts for a specific OID
  explain                  print a hexdump of a GME file with descriptions
  holes                    lists all unknown parts of the file.
  rewrite                  parses the file and reads it again (for debugging)

  GME extraction commands: 
  media                    dumps all audio samples
  binaries                 dumps all binaries

  Simulation commands:     
  play                     interactively play a GME file

and the code is:

    cmd = subparser $ mconcat
        [ cmdSep "GME creation commands:"
        , assembleCmd
        , cmdSep ""

        , cmdSep "OID code creation commands:"
        , oidTableCmd
        , oidCodesCmd
        , oidCodeCmd
        , cmdSep ""

        , cmdSep "GME analysis commands:"
        , infoCmd
        , exportCmd
        , scriptsCmd
        , scriptCmd
        , gamesCmd
        , lintCmd
        , segmentsCmd
        , segmentCmd
        , explainCmd
        , holesCmd
        , rewriteCmd
        , cmdSep ""

        , cmdSep "GME extraction commands:"
        , mediaCmd
        , binariesCmd
        , cmdSep ""

        , cmdSep "Simulation commands:"
        , playCmd
        ]

cmdSep :: String -> Mod CommandFields a
cmdSep s = command s $ info empty mempty

It breaks if people run ./tttool "" or ./tttool "Simulation commands:", but it’s a start.

@HuwCampbell
Copy link
Collaborator

Closing as #197 is a solution to this,

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

4 participants