Autogenerate list of formats for --help

This commit is contained in:
Vidar Holen 2017-08-06 15:48:59 -07:00
parent 72ed234291
commit 73d06c4f47
1 changed files with 7 additions and 2 deletions

View File

@ -35,6 +35,7 @@ import Data.Bits
import Data.Char
import Data.Functor
import Data.Either
import Data.List
import qualified Data.Map as Map
import Data.Maybe
import Data.Monoid
@ -77,8 +78,8 @@ options = [
Option "e" ["exclude"]
(ReqArg (Flag "exclude") "CODE1,CODE2..") "exclude types of warnings",
Option "f" ["format"]
(ReqArg (Flag "format") "FORMAT")
"output format (checkstyle, gcc, json, tty)",
(ReqArg (Flag "format") "FORMAT") $
"output format (" ++ formatList ++ ")",
Option "C" ["color"]
(OptArg (maybe (Flag "color" "always") (Flag "color")) "WHEN")
"Use color (auto, always, never)",
@ -109,6 +110,10 @@ formats options = Map.fromList [
("tty", ShellCheck.Formatter.TTY.format options)
]
formatList = intercalate ", " names
where
names = Map.keys $ formats (formatterOptions defaultOptions)
getOption [] _ = Nothing
getOption (Flag var val:_) name | name == var = return val
getOption (_:rest) flag = getOption rest flag