gpt4 book ai didi

haskell - optparse-applicative 子命令帮助文本

转载 作者:行者123 更新时间:2023-12-05 09:21:01 25 4
gpt4 key购买 nike

我正在使用 stackage lts 5.1 附带的 optparse-applicative我有一个带有子命令的解析器,我已经描述了它们的选项的帮助文本,但它们没有显示。

这是我使用 --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

代码:

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

最佳答案

正如 Zeta 指出的那样,单个命令的描述显示在 <executable> <command> --help 上。 .但是为了让它起作用,在optparse-applicative选项 --help 的解析器每个命令的子解析器都需要。您只为 <executable> --help 定义了一个(请参阅您的 haskell 代码块的第二行)。如果没有针对特定命令的帮助解析器,<executable> <command> --help 的输出不会是帮助消息,而是关于 invalid option --help 的通知和使用说明。

一般模式是按顺序为 --help 应用解析器选项,即 helper , 到命令参数的解析器,如下所示:command "command-name" (info (yourCommandArgParser <**> helper) (fullDesc <> progDesc "your commands description" <> ...)) .

所以对于 export你可以写的命令:

argCmdExport = command "export" infos
where
infos = info (options <**> helper) desc
desc = progDesc "text4"
options = ArgCmdExport <$>
argModeExport <*>
argTableExport <*>
argOptExport

附言。这个问题很老,但是当我遇到同样的问题时,我偶然发现了它。而且网络上仍然没有关于它的任何信息。

关于haskell - optparse-applicative 子命令帮助文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35414140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com