Skip to content

Commit

Permalink
Reduce string to bool flag fn
Browse files Browse the repository at this point in the history
  • Loading branch information
cbclemmer authored and mergify[bot] committed Oct 21, 2022
1 parent c5c55fb commit d0548eb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
7 changes: 0 additions & 7 deletions Cabal/src/Distribution/Simple/Flag.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module Distribution.Simple.Flag (
flagToMaybe,
flagToList,
maybeToFlag,
maybeStringToBoolFlag,
BooleanFlag(..) ) where

import Prelude ()
Expand Down Expand Up @@ -125,12 +124,6 @@ maybeToFlag :: Maybe a -> Flag a
maybeToFlag Nothing = NoFlag
maybeToFlag (Just x) = Flag x

maybeStringToBoolFlag :: Maybe String -> Flag Bool
maybeStringToBoolFlag Nothing = NoFlag
maybeStringToBoolFlag (Just "True") = Flag True
maybeStringToBoolFlag (Just "False") = Flag False
maybeStringToBoolFlag _ = NoFlag

-- | Types that represent boolean flags.
class BooleanFlag a where
asBool :: a -> Bool
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import Distribution.Simple.Configure
import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.Flag
( Flag(..), toFlag, flagToMaybe, flagToList, maybeToFlag
, flagElim, fromFlagOrDefault, maybeStringToBoolFlag
, flagElim, fromFlagOrDefault
)
import Distribution.Simple.Setup
( ConfigFlags(..), BuildFlags(..), ReplFlags
Expand Down Expand Up @@ -364,7 +364,7 @@ globalCommand commands = CommandUI {
,multiOption "nix"
globalNix (\v flags -> flags { globalNix = v })
[
optArg' "(True or False)" maybeStringToBoolFlag (\case
optArg' "(True or False)" (maybeToFlag . (readMaybe =<<)) (\case
Flag True -> [Just "enable"]
Flag False -> [Just "disable"]
NoFlag -> [Just "disable"]) "" ["nix"]
Expand Down

0 comments on commit d0548eb

Please sign in to comment.