Skip to content

Commit

Permalink
Merge pull request #1829 from hololeap/allow-new-optparse
Browse files Browse the repository at this point in the history
`yesod-bin`: Support `optparse-applicative-0.18`
  • Loading branch information
snoyberg authored Feb 10, 2024
2 parents b240282 + e212096 commit d3618b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
4 changes: 4 additions & 0 deletions yesod-bin/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog for yesod-bin

## 1.6.2.3

* Support optparse-applicative-0.18 [#1829](https://github.com/yesodweb/yesod/pull/1829)

## 1.6.2.2

* Support Cabal 3.8 [#1769](https://github.com/yesodweb/yesod/pull/1769)
Expand Down
27 changes: 17 additions & 10 deletions yesod-bin/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,16 @@ configLines = mapMaybe (mkLine . takeWhile (/='#')) . lines
injectDefaultP :: M.Map [String] String -> [String] -> Parser a -> Parser a
injectDefaultP _env _path n@(NilP{}) = n
injectDefaultP env path p@(OptP o)
#if MIN_VERSION_optparse_applicative(0,13,0)
#if MIN_VERSION_optparse_applicative(0,18,0)
| (Option (CmdReader _ ts) props) <- o =
let ts' = map (\(cmd,parseri) -> (cmd, modifyParserI cmd parseri)) ts
in OptP (Option (CmdReader Nothing ts') props)
#elif MIN_VERSION_optparse_applicative(0,13,0)
| (Option (CmdReader _ cmds f) props) <- o =
OptP (Option (CmdReader Nothing cmds (`M.lookup` cmdMap f cmds)) props)
#else
| (Option (CmdReader cmds f) props) <- o =
#endif
let cmdMap = M.fromList (map (\c -> (c, mkCmd c)) cmds)
mkCmd cmd =
let (Just parseri) = f cmd
in parseri { infoParser = injectDefaultP env (path ++ [normalizeName cmd]) (infoParser parseri) }
#if MIN_VERSION_optparse_applicative(0,13,0)
in OptP (Option (CmdReader Nothing cmds (`M.lookup` cmdMap)) props)
#else
in OptP (Option (CmdReader cmds (`M.lookup` cmdMap)) props)
OptP (Option (CmdReader cmds (`M.lookup` cmdMap f cmds)) props)
#endif
| (Option (OptReader names (CReader _ rdr) _) _) <- o =
p <|> either (const empty)
Expand All @@ -91,6 +88,16 @@ injectDefaultP env path p@(OptP o)
| (Option (FlagReader names a) _) <- o =
p <|> if any ((==Just "1") . getEnvValue env path) names then pure a else empty
| otherwise = p
where
modifyParserI cmd parseri =
parseri { infoParser = injectDefaultP env (path ++ [normalizeName cmd]) (infoParser parseri) }
cmdMap f cmds =
let mkCmd cmd =
let (Just parseri) = f cmd
in modifyParserI cmd parseri
in M.fromList (map (\c -> (c, mkCmd c)) cmds)


injectDefaultP env path (MultP p1 p2) =
MultP (injectDefaultP env path p1) (injectDefaultP env path p2)
injectDefaultP env path (AltP p1 p2) =
Expand Down
2 changes: 1 addition & 1 deletion yesod-bin/yesod-bin.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yesod-bin
version: 1.6.2.2
version: 1.6.2.3
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand Down

0 comments on commit d3618b0

Please sign in to comment.