diff --git a/yesod-bin/Options.hs b/yesod-bin/Options.hs index 25b3d940..c180f31b 100644 --- a/yesod-bin/Options.hs +++ b/yesod-bin/Options.hs @@ -71,7 +71,7 @@ injectDefaultP env path p@(OptP o) in parseri { infoParser = injectDefaultP env (path ++ [normalizeName cmd]) (infoParser parseri) } in OptP (Option (CmdReader cmds (`M.lookup` cmdMap)) props) | (Option (OptReader names (CReader _ rdr) _) _) <- o = - p <|> either (const empty) pure (msum $ map (rdr <=< (maybe (Left $ ErrorMsg "Missing environment variable") Right . getEnvValue env path)) names) + p <|> either' (const empty) pure (msum $ map (rdr <=< (maybe (left $ ErrorMsg "Missing environment variable") right . getEnvValue env path)) names) | (Option (FlagReader names a) _) <- o = p <|> if any ((==Just "1") . getEnvValue env path) names then pure a else empty | otherwise = p @@ -81,6 +81,16 @@ injectDefaultP env path (AltP p1 p2) = AltP (injectDefaultP env path p1) (injectDefaultP env path p2) injectDefaultP _env _path b@(BindP {}) = b +#if MIN_VERSION_optparse_applicative(0,6,0) +right = ReadM . Right +left = ReadM . Left +either' f g (ReadM x) = either f g x +#else +right = Right +left = Left +either' = either +#endif + getEnvValue :: M.Map [String] String -> [String] -> OptName -> Maybe String getEnvValue env path (OptLong l) = M.lookup (path ++ [normalizeName l]) env getEnvValue _ _ _ = Nothing diff --git a/yesod-bin/main.hs b/yesod-bin/main.hs index 3c5ff739..f0f4e4b0 100755 --- a/yesod-bin/main.hs +++ b/yesod-bin/main.hs @@ -16,6 +16,9 @@ import qualified Paths_yesod_bin import Scaffolding.Scaffolder import Options.Applicative.Builder.Internal (Mod, OptionFields) +#if MIN_VERSION_optparse_applicative(0,6,0) +import Options.Applicative.Types (ReadM (ReadM)) +#endif #ifndef WINDOWS import Build (touch) @@ -165,7 +168,11 @@ optStr :: Mod OptionFields (Maybe String) -> Parser (Maybe String) optStr m = nullOption $ value Nothing <> reader (success . str) <> m where +#if MIN_VERSION_optparse_applicative(0,6,0) + success = ReadM . Right +#else success = Right +#endif -- | Like @rawSystem@, but exits if it receives a non-success result. rawSystem' :: String -> [String] -> IO () diff --git a/yesod-bin/yesod-bin.cabal b/yesod-bin/yesod-bin.cabal index cc27d0f1..b65134b4 100644 --- a/yesod-bin/yesod-bin.cabal +++ b/yesod-bin/yesod-bin.cabal @@ -1,5 +1,5 @@ name: yesod-bin -version: 1.2.3.3 +version: 1.2.3.4 license: MIT license-file: LICENSE author: Michael Snoyman