|
34 | 34 | import Data.Char (toLower) |
35 | 35 | import Data.List (intersperse) |
36 | 36 | import Data.String (IsString (..)) |
37 | | -import Data.Text (Text, pack) |
38 | | -import Data.Yaml (FromJSON, ToJSON (toJSON)) |
| 37 | +import Data.Text (Text, pack, unpack) |
| 38 | +import Data.Yaml (FromJSON(..), ToJSON (toJSON), withText) |
39 | 39 | import GHC.Generics (Generic) |
40 | 40 | import System.FilePath (splitFileName) |
41 | 41 | import System.Info (os) |
@@ -229,12 +229,16 @@ instance IsString SaveFormat where |
229 | 229 | mconcat |
230 | 230 | [ s, |
231 | 231 | " is not one of the valid save formats : ", |
232 | | - mconcat $ intersperse ", " $ show <$> saveFormats |
| 232 | + mconcat $ intersperse ", " $ show <$> saveFormats, |
| 233 | + " (and lowercase variations). " |
233 | 234 | ] |
234 | 235 | where |
235 | 236 | saveFormats = enumFromTo minBound maxBound :: [SaveFormat] |
236 | 237 |
|
237 | | -instance FromJSON SaveFormat |
| 238 | +-- | Use the IsString instance to parse JSON so that the parsing is flexible |
| 239 | +-- with respect to uppercase/lowercase (#42) |
| 240 | +instance FromJSON SaveFormat where |
| 241 | + parseJSON = withText "SaveFormat" (pure . fromString . unpack) |
238 | 242 |
|
239 | 243 | instance ToJSON SaveFormat where |
240 | 244 | toJSON = toJSON . extension |
|
0 commit comments