|
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) |
@@ -232,12 +232,16 @@ instance IsString SaveFormat where |
232 | 232 | mconcat |
233 | 233 | [ s, |
234 | 234 | " is not one of the valid save formats : ", |
235 | | - mconcat $ intersperse ", " $ show <$> saveFormats |
| 235 | + mconcat $ intersperse ", " $ show <$> saveFormats, |
| 236 | + " (and lowercase variations). " |
236 | 237 | ] |
237 | 238 | where |
238 | 239 | saveFormats = enumFromTo minBound maxBound :: [SaveFormat] |
239 | 240 |
|
240 | | -instance FromJSON SaveFormat |
| 241 | +-- | Use the IsString instance to parse JSON so that the parsing is flexible |
| 242 | +-- with respect to uppercase/lowercase (#42) |
| 243 | +instance FromJSON SaveFormat where |
| 244 | + parseJSON = withText "SaveFormat" (pure . fromString . unpack) |
241 | 245 |
|
242 | 246 | instance ToJSON SaveFormat where |
243 | 247 | toJSON = toJSON . extension |
|
0 commit comments