@@ -10,14 +10,16 @@ import Data.Semigroup ( Semigroup(..) )
1010#endif
1111
1212import Options.Applicative
13− ( Parser
14− , action, execParser, header, help, helper, info
15− , metavar, strArgument, value
13+ ( Parser, (<|>)
14+ , action, execParser, footerDoc, headerDoc, help, helper, hidden, info
15+ , long, metavar, short, strArgument, strOption, value
1616 )
17+import Options.Applicative.Help.Pretty
18+ ( vcat, text )
1719
1820import System.Exit ( die )
1921
20−import Common ( dashToNothing, versionOption, numericVersionOption )
22+import Common ( dashToNothing, versionText, versionOption, numericVersionOption )
2123
2224data Options = Options
2325 { optInput :: Maybe FilePath
@@ -37,9 +39,22 @@ options :: IO Options
3739options =
3840 execParser $
3941 info (helper <*> versionOption self <*> numericVersionOption <*> programOptions)
40− (header "Reads a JSON document and writes it out as YAML document.")
42+ $ headerDoc hdoc
43+ <> footerDoc fdoc
4144
4245 where
46+ hdoc = Just $ vcat $ map text
47+ [ versionText self
48+ , ""
49+ , "Reads a JSON document and writes it out as YAML document."
50+ ]
51+ fdoc = Just $ text $ concat
52+ [ "The old call pattern '"
53+ , self
54+ , " IN OUT' is also accepted, but deprecated."
55+ ]
56+
57+ programOptions :: Parser Options
4358 programOptions = Options <$> oInput <*> oOutput
4459
4560 oInput :: Parser (Maybe FilePath)
@@ -48,15 +63,29 @@ options =
4863 $ metavar "IN"
4964 <> value "-"
5065 <> action "file"
51− <> help "The input file containing the JSON document; use '-' for stdin."
66+ <> help "The input file containing the JSON document; use '-' for stdin (default)."
5267
5368 oOutput :: Parser (Maybe FilePath)
5469 oOutput = dashToNothing <$> do
70+ oOutputExplicit <|> oOutputImplicit
71+
72+ oOutputExplicit :: Parser FilePath
73+ oOutputExplicit =
74+ strOption
75+ $ long "output"
76+ <> short 'o'
77+ <> metavar "OUT"
78+ <> action "file"
79+ -- <> help "The file to hold the produced YAML document; use '-' for stdout (default)."
80+
81+ oOutputImplicit :: Parser FilePath
82+ oOutputImplicit =
5583 strArgument
5684 $ metavar "OUT"
5785 <> value "-"
5886 <> action "file"
59− <> help "The file to hold the produced YAML document; use '-' for stdout."
87+ <> hidden
88+ <> help "The file to hold the produced YAML document; use '-' for stdout (default)."
6089
6190-- | Exit with 'self'-stamped error message.
6291