Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add Config.Dyre.Options.removeDyreOptions #7

Merged
merged 1 commit into from

2 participants

Reiner Pope Will Donnelly
Reiner Pope

This is a pure variant of 'withDyreOptions', which (more importantly) doesn't require a 'Params' argument.

In Yi, we process commandline arguments before running Dyre, and we build the Params based on the result of commandline argument processing. We need removeDyreOptions to write something like this:

yi cfg = do
   args <- getArgs
   let params = processArgs (removeDyreOptions args)
   wrapMain params cfg

Without removeDyreOptions, we are forced to use 'withDyreOptions' with a dummy Params object.

Will Donnelly willdonnelly merged commit 54d3318 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 24, 2011
  1. Reiner Pope
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 4 deletions.
  1. +8 −4 Config/Dyre/Options.hs
12 Config/Dyre/Options.hs
View
@@ -17,7 +17,8 @@ control over to a new binary, it gets an argument list which
preserves the important flags with a call to 'customOptions'.
-}
module Config.Dyre.Options
- ( withDyreOptions
+ ( removeDyreOptions
+ , withDyreOptions
, customOptions
, getDenyReconf
, getForceReconf
@@ -34,6 +35,11 @@ import System.Environment.Executable
import Config.Dyre.Params
+-- | Remove all Dyre's options from the given commandline arguments.
+removeDyreOptions :: [String] -> [String]
+removeDyreOptions = filter $ not . prefixElem dyreArgs
+ where prefixElem xs = or . zipWith ($) (map isPrefixOf xs) . repeat
+
-- | Store Dyre's command-line options to the IO-Store "dyre",
-- and then execute the provided IO action with all Dyre's
-- options removed from the command-line arguments.
@@ -57,9 +63,7 @@ withDyreOptions Params{configCheck = check} action = withStore "dyre" $ do
putValue "dyre" "debugMode" $ "--dyre-debug" `elem` args
-- We filter the arguments, so now Dyre's arguments 'vanish'
- withArgs (filterArgs args) action
- where filterArgs = filter $ not . prefixElem dyreArgs
- prefixElem xs = or . zipWith ($) (map isPrefixOf xs) . repeat
+ withArgs (removeDyreOptions args) action
-- | Get the value of the '--force-reconf' flag, which is used
-- to force a recompile of the custom configuration.
Something went wrong with that request. Please try again.