Skip to content

Commit

Permalink
Use where instead of let for setting up aeson config.
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Sep 5, 2022
1 parent cfaa3f5 commit 18b2f48
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Stack/ConfigCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ encodeDumpProject rawConfig format p
| ConfigDumpYaml <- format = dumpProject (\e d ->
either (const e) encodeUtf8 (cfgRedress rawConfig d ""))
| ConfigDumpJson <- format = dumpProject (\_ d ->
let cmp = cfgKeyCompare rawConfig d ""
in toStrictBytes $ encodePretty' (Aeson.defConfig{confCompare = cmp}) d)
toStrictBytes $ encodePretty' (cfgPretty d) d)
where
-- REVIEW: Is there a way to encode straight to keymap?
-- encode project to bytestring then decode to keymap.
dumpProject f = let e = Yaml.encode p in Yaml.decodeEither' e &
either (const e) (\(d :: KeyMap Yaml.Value) -> f e d)

cfgPretty d = Aeson.defConfig{confCompare = cfgKeyCompare rawConfig d ""}

cfgKeyCompare :: RawYaml -> KeyMap Yaml.Value -> Text -> (Text -> Text -> Ordering)
cfgKeyCompare (yamlLines -> configLines) (fmap Key.toText . KeyMap.keys -> keys) cmdKey =
compareInOrder configLines (coerce keys) (coerce cmdKey)
Expand Down

0 comments on commit 18b2f48

Please sign in to comment.