You can use optparse-applicative . The most common usage pattern looks like this (I just copy and paste from a small utility that I use):
options :: Parser (String, String) options = (,) <$> (strOption $ mconcat [ short 'n', long "node", metavar "NODE", value "127.0.0.1", showDefaultWith id, completer (bashCompleter "hostname"), help "AMQP node to connect to" ] ) <*> (strOption $ mconcat [ short 'q', long "queue", metavar "QUEUE", value "1.0.0", showDefaultWith id, help "Queue to initialize" ] ) main = do (hostName, queue) <- execParser $ info (helper <*> options) $ mconcat [ fullDesc, header "The Suns setup utility", progDesc "Sets up an AMQP node", footer "Report bugs to Gabriel439@gmail.com " ] ...
When I run the compiled program with -h , I get:
$ suns-admin -h The Suns setup utility Usage: suns-admin [-n|--node NODE] [-q|--queue QUEUE] Sets up an AMQP node Available options: -h,--help Show this help text -n,--node NODE AMQP node to connect to (default: 127.0.0.1) -q,--queue QUEUE Queue to initialize (default: 1.0.0) Report bugs to Gabriel439@gmail.com
This gives you an idea of ββsome great options you can play with and the good output that the program generates.
Gabriel gonzalez
source share