diff --git a/yesod-bin/ChangeLog.md b/yesod-bin/ChangeLog.md index 106debb49..50857a606 100644 --- a/yesod-bin/ChangeLog.md +++ b/yesod-bin/ChangeLog.md @@ -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) diff --git a/yesod-bin/Options.hs b/yesod-bin/Options.hs index 4748509e2..221a60b77 100644 --- a/yesod-bin/Options.hs +++ b/yesod-bin/Options.hs @@ -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) @@ -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) = diff --git a/yesod-bin/yesod-bin.cabal b/yesod-bin/yesod-bin.cabal index e54ed29c9..e2d490ddf 100644 --- a/yesod-bin/yesod-bin.cabal +++ b/yesod-bin/yesod-bin.cabal @@ -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