Search code examples
shake-build-system

How to override Shake configuration on the command-line


I maintain small configuration files per project read via usingConfigFile. I'd like to be able to override any of those settings on the command line. It seems using shakeArgsWith (rather than shakeArgs) is the first step on the way but I don't see an obvious way to wire that through to the values produced by getConfig. Is there a standard approach for doing this?


Solution

  • There isn't a standard approach, but I know several larger build systems have invented something. A combination of shakeArgsWith, readConfigFile and usingConfig should do it. Something like (untested):

    main = shakeArgsWith shakeOptions [] $ \_ args -> return $ Just $ do
        file <- readConfigFile "myfile.cfg"
        usingConfig $ Map.union (argsToSettings args) file
        myNormalRules
    

    Where argsToSettings is some function that parses your arguments and turns them into settings - e.g. breaking on the first = symbol or similar.