How to specify names for missing commands in the help message generated by optparse-applyative?

I am trying to use the Hackage optparse-applicative package and the question of how to specify a specific aspect of the help message displayed when the program starts with insufficient specified commands.

The following sample illustration illustrates my problem. When launched from the command line, one of two commands is required as input. That is, it is designed to run either as $ program com1, or $ program com2.

module Main where

import Options.Applicative
import Data.Semigroup ((<>))

data Command = Com1
             | Com2

com1 :: Parser Command
com1 = subparser $ command "com1" $ info (pure Com1) fullDesc

com2 :: Parser Command
com2 = subparser $ command "com2" $ info (pure Com2) fullDesc

commandParser :: Parser Command
commandParser = com1
            <|> com2

runCommand :: Command -> IO ()
runCommand Com1 = putStrLn ">>> Com1 <<<"
runCommand Com2 = putStrLn ">>> Com2 <<<"

opts :: ParserInfo Command
opts = info (commandParser <**> helper)
  $ fullDesc  
  <> progDesc "=== progDesc ==="
  <> header "=== header ==="
  <> footer "=== footer ==="

main :: IO ()
main = runCommand =<< execParser opts

If this program is started without specifying the command com1and com2, a help message is displayed.

$ program
Missing: (COMMAND | COMMAND)

Usage: options-applicative-example-exe (COMMAND | COMMAND)
  === progDesc ===

(COMMAND | COMMAND) (com1 | com2), , .

--help, $ program --help, .

$ program --help
=== header ===

Usage: options-applicative-example-exe (COMMAND | COMMAND)
  === progDesc ===

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

Available commands:
  com1
  com2

=== footer ===

com1 com2 " ". , , , (com1 | com2) (COMMAND | COMMAND).

(com1 | com2) (COMMAND | COMMAND)?

+6
1

, metavar .

com1 = subparser $ mconcat
  [ metavar c
  , command c $ info (pure Com1) fullDesc)
  ] where c = "com1"

, optparse-applicative command , subparser , command metavar " ".

+7

All Articles