I'm using optparse-applicative that comes with stackage lts 5.1 I have a parser with subcommands and I have described a help text for their options, but they don't show.
This is the output when I run the executable with --help
:
[david@devcentos65 manipro]$ /home/david/.local/bin/manipro --help
manipro - text1
Usage: manipro COMMAND [-v|--verbose] text2
Available options:
-h,--help Show this help text
-v,--verbose text3
Available commands:
export text4
dico text9
The code :
parserArgs :: ParserInfo ArgApp
parserArgs = info (helper <*> args) desc
where
desc =
fullDesc <>
progDesc "text1" <>
header "text2"
args = ArgApp <$> argCmd <*> optverbose
where
optverbose = switch (
short 'v' <> long "verbose" <>
help "text3" )
argCmd = subparser (argCmdExport <> argCmdDico)
argCmdExport = command "export" infos
where
infos = info options desc
desc = progDesc "text4"
options = ArgCmdExport <$>
argModeExport <*>
argTableExport <*>
argOptExport
argModeExport = argument auto (metavar "FORMAT")
argTableExport = argument text (metavar "TABLE")
argOptExport = ArgOptExport <$> optional noesc <*> optional cols <*>
ens <*> tst
where
noesc = option textList (long "noesc" <> metavar "CHAMPS" <> help "text5" )
cols = option textList (long "cols" <> metavar "CHAMPS" <> help "text6" )
ens = flag EnsEtoile EnsDollar (short 'd' <> long "dollar" <>
help "text7")
tst = flag False True (short 't' <> long "test" <>
help "text8")
argCmdDico = command "dico" infos
where
infos = info options desc
desc = progDesc "text9"
options = ArgCmdDico <$>
argOptDico
argOptDico = ArgOptDico <$> optional tables
where
tables = option textList (long "tables" <> metavar "TABLES" <>
help "text10" )
text = str >>= return . pack
textList = str >>= return . splitOn "," . pack
optparse-applicative
hides the detailed description of a command deliberately if you only use--help
. After all, you might have a dozen commands. For example,stack
has 34. Listing probably fills your terminal vertically. If it displayed all possible arguments, you would end up with a lot of text.Instead,
--help
will only show the common arguments and a list of commands. In order to show the description of a single command, you have to use<executable> <command> --help
:This reduces the clutter somewhat. It also follows the same rules as other popular multi-command applications, such as
git
andhg
(with the small exception that<executable> --help <command>
will still show only the general help).