Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: haskell/cabal
...
head fork: 23Skidoo/cabal
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 01, 2013
@23Skidoo 23Skidoo Add syntax for setting an OptArg option to the default value.
Makes it possible to write 'jobs: $DEFAULT' in the config file, which is
equivalent to running 'cabal install -j' from the command line (the number of
working threads is set to the number of processors).
01a3da6
Showing with 13 additions and 4 deletions.
  1. +13 −4 Cabal/Distribution/Simple/Command.hs
View
17 Cabal/Distribution/Simple/Command.hs
@@ -166,7 +166,8 @@ reqArg ad mkflag showflag sf lf d get set =
optArg :: Monoid b => ArgPlaceHolder -> ReadE b -> b -> (b -> [Maybe String])
-> MkOptDescr (a -> b) (b -> a -> a) a
optArg ad mkflag def showflag sf lf d get set =
- OptArg d (sf,lf) ad (fmap (\a b -> set (get b `mappend` a) b) mkflag)
+ OptArg d (sf,lf) ad (fmap (\a b -> set (get b `mappend` a) b)
+ (withDefaultValue def mkflag))
(\b -> set (get b `mappend` def) b)
(showflag . get)
@@ -255,7 +256,7 @@ viewAsFieldDescr (OptionField n dd) = FieldDescr n get set
OptArg _ _ _ _ _ ppr ->
case ppr t of
[] -> empty
- (Nothing : _) -> text "True"
+ (Nothing : _) -> text "$DEFAULT"
(Just a : _) -> text a
ChoiceOpt alts ->
fromMaybe empty $ listToMaybe
@@ -272,8 +273,8 @@ viewAsFieldDescr (OptionField n dd) = FieldDescr n get set
_ -> syntaxError line val
BoolOpt _ _ _ setV _ -> (`setV` a) `liftM` runP line n parse val
OptArg _ _ _ readE _ _ -> ($ a) `liftM` runE line n readE val
- -- Optional arguments are parsed just like required arguments here;
- -- we don't provide a method to set an OptArg field to the default value.
+ -- A special value @$DEFAULT@ is used for setting an 'OptArg' field to
+ -- the default value (see 'withDefaultValue').
getChoiceByLongFlag :: OptDescr b -> String -> Maybe (b->b)
getChoiceByLongFlag (ChoiceOpt alts) val = listToMaybe [ set | (_,(_sf,lf:_), set, _) <- alts
@@ -554,3 +555,11 @@ noExtraFlags extraFlags =
die $ "Unrecognised flags: " ++ intercalate ", " extraFlags
--TODO: eliminate this function and turn it into a variant on commandAddAction
-- instead like commandAddActionNoArgs that doesn't supply the [String]
+
+-- | Turn a 'ReadE' parser into a parser that returns the provided default value
+-- if given the special value @$DEFAULT@.
+withDefaultValue :: b -> ReadE b -> ReadE b
+withDefaultValue def (ReadE f) = ReadE f'
+ where
+ f' "$DEFAULT" = Right def
+ f' str = f str

No commit comments for this range

Something went wrong with that request. Please try again.