2020-11-08 07:13:58 +03:00
|
|
|
{-# LANGUAGE ApplicativeDo #-}
|
|
|
|
{-# LANGUAGE RecordWildCards #-}
|
|
|
|
{-# LANGUAGE LambdaCase #-}
|
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
module Flags where
|
|
|
|
|
|
|
|
import Options.Applicative
|
|
|
|
import JsonToHaskell
|
|
|
|
import Text.RawString.QQ (r)
|
2020-11-08 07:31:46 +03:00
|
|
|
import Text.PrettyPrint.ANSI.Leijen
|
2020-11-08 07:13:58 +03:00
|
|
|
|
|
|
|
optionsParserInfo :: ParserInfo Options
|
2020-11-08 07:24:53 +03:00
|
|
|
optionsParserInfo = info (optionParser <**> helper) fullDesc
|
2020-11-08 07:13:58 +03:00
|
|
|
|
|
|
|
parseNumberType :: ReadM NumberType
|
|
|
|
parseNumberType = maybeReader $ \case
|
|
|
|
"smart-floats" -> Just UseSmartFloats
|
|
|
|
"smart-doubles" -> Just UseSmartDoubles
|
|
|
|
"floats" -> Just UseFloats
|
|
|
|
"doubles" -> Just UseDoubles
|
|
|
|
_ -> Nothing
|
|
|
|
|
|
|
|
parseTextType :: ReadM TextType
|
|
|
|
parseTextType = maybeReader $ \case
|
|
|
|
"string" -> Just UseString
|
|
|
|
"text" -> Just UseText
|
|
|
|
"bytestring" -> Just UseByteString
|
|
|
|
_ -> Nothing
|
|
|
|
|
|
|
|
parseMapType :: ReadM MapType
|
|
|
|
parseMapType = maybeReader $ \case
|
|
|
|
"map" -> Just UseMap
|
|
|
|
"hashmap" -> Just UseHashMap
|
|
|
|
_ -> Nothing
|
|
|
|
|
|
|
|
parseListType :: ReadM ListType
|
|
|
|
parseListType = maybeReader $ \case
|
|
|
|
"list" -> Just UseList
|
|
|
|
"vector" -> Just UseVector
|
|
|
|
_ -> Nothing
|
|
|
|
|
2020-11-08 07:31:46 +03:00
|
|
|
stringDoc :: String -> Mod f a
|
|
|
|
stringDoc = helpDoc . Just . string
|
2020-11-08 07:13:58 +03:00
|
|
|
|
|
|
|
optionParser :: Parser Options
|
|
|
|
optionParser = do
|
|
|
|
_tabStop <- option auto
|
|
|
|
(short 't'
|
|
|
|
<> long "tab-stop"
|
2020-11-08 07:31:46 +03:00
|
|
|
<> stringDoc "Number of spaces to indent each level."
|
2020-11-08 07:13:58 +03:00
|
|
|
<> value 2)
|
|
|
|
_numberType <- option parseNumberType
|
|
|
|
(short 'n'
|
|
|
|
<> long "numbers"
|
|
|
|
<> value UseSmartDoubles
|
2020-11-08 07:31:46 +03:00
|
|
|
<> stringDoc [r|Type to use for numbers.
|
|
|
|
|
2020-11-08 07:13:58 +03:00
|
|
|
'smart-floats':
|
2020-11-08 07:31:46 +03:00
|
|
|
Use floats for numbers with decimals, Int for whole numbers.
|
2020-11-08 07:13:58 +03:00
|
|
|
'smart-doubles':
|
2020-11-08 07:31:46 +03:00
|
|
|
Use floats for numbers with decimals, Int for whole numbers.
|
2020-11-08 07:13:58 +03:00
|
|
|
'floats':
|
2020-11-08 07:31:46 +03:00
|
|
|
Use floats for all numbers.
|
2020-11-08 07:13:58 +03:00
|
|
|
'doubles':
|
2020-11-08 07:31:46 +03:00
|
|
|
Use doubles for all numbers.
|
2020-11-08 07:13:58 +03:00
|
|
|
'scientific':
|
2020-11-08 07:31:46 +03:00
|
|
|
Use scientific for all numbers.
|
2020-11-08 07:13:58 +03:00
|
|
|
|])
|
|
|
|
_textType <- option parseTextType
|
|
|
|
(short 's'
|
|
|
|
<> long "strings"
|
|
|
|
<> value UseText
|
2020-11-08 07:31:46 +03:00
|
|
|
<> stringDoc [r|Type to use for strings.
|
|
|
|
|
2020-11-08 07:13:58 +03:00
|
|
|
'string':
|
|
|
|
Use String for strings.
|
|
|
|
'text':
|
|
|
|
Use Text for strings.
|
|
|
|
'bytestring':
|
|
|
|
Use ByteString for strings.
|
|
|
|
|])
|
|
|
|
_mapType <- option parseMapType
|
|
|
|
(short 'm'
|
|
|
|
<> long "maps"
|
|
|
|
<> value UseMap
|
2020-11-08 07:31:46 +03:00
|
|
|
<> stringDoc [r|Type to use for maps.
|
|
|
|
|
2020-11-08 07:13:58 +03:00
|
|
|
'map':
|
|
|
|
Use Data.Map for maps.
|
|
|
|
'hashmap':
|
|
|
|
Use Data.HashMap for maps.
|
|
|
|
|])
|
|
|
|
_listType <- option parseListType
|
|
|
|
(short 'l'
|
|
|
|
<> long "lists"
|
|
|
|
<> value UseList
|
2020-11-08 07:31:46 +03:00
|
|
|
<> stringDoc [r|Type to use for lists.
|
|
|
|
|
2020-11-08 07:13:58 +03:00
|
|
|
'list':
|
|
|
|
Use [] for lists.
|
|
|
|
'vector':
|
|
|
|
Use Data.Vector for lists.
|
|
|
|
|])
|
|
|
|
_includeHeader <- flag True False
|
|
|
|
(long "no-module-header"
|
2020-11-08 07:31:46 +03:00
|
|
|
<> stringDoc [r|Omit the module header containing language extensions, module definition and imports.|])
|
2020-11-08 08:03:01 +03:00
|
|
|
_includeInstances <- flag True False
|
|
|
|
(long "no-instances"
|
|
|
|
<> stringDoc [r|Omit the ToJSON and FromJSON instances.|])
|
2020-11-08 08:50:45 +03:00
|
|
|
_prefixRecordFields <- flag True False
|
|
|
|
(long "no-prefix-record-fields"
|
|
|
|
<> stringDoc [r|Omit record field prefixes.|])
|
2020-11-08 07:13:58 +03:00
|
|
|
_strictData <- flag False True
|
|
|
|
(long "strict"
|
2020-11-08 07:31:46 +03:00
|
|
|
<> stringDoc [r|Use strict record fields.|])
|
2020-11-08 07:13:58 +03:00
|
|
|
pure $ Options {.. }
|