shake: refactor; use only the first argument as build target

This commit is contained in:
Simon Michael 2020-09-04 16:24:42 -07:00
parent a5fcb19bb0
commit ab9e50003c

View File

@ -116,6 +116,8 @@ towebmd = "-t markdown-smart-fenced_divs-fenced_code_attributes-simple_tables-mu
main = do
-- 1. gather some IO values used by rules
-- hledger manual also includes the markdown files from here:
let commandsdir = "hledger/Hledger/Cli/Commands"
commandmds <-
@ -126,13 +128,14 @@ main = do
let sitedir = "site"
pages <- map takeBaseName . filter (".md" `isSuffixOf`) <$> S.getDirectoryContents sitedir
shakeArgs
shakeOptions
{
shakeVerbosity=Quiet
-- ,shakeReport=[".shake.html"]
}
$ do
args <- getArgs
let args2 = drop 1 args
-- 2. define the shake rules
let
rules :: Rules ()
rules = do
want ["help"]
@ -678,6 +681,24 @@ main = do
putNormal "Cleaning shake build cache"
removeFilesAfter ".shake" ["//*"]
-- 3. run the shake rule selected by the first command line argument,
-- leaving the other args for the rule to use
let
opts = shakeOptions{
shakeVerbosity=Quiet
-- ,shakeReport=[".shake.html"]
}
runWithArgs :: Rules () -> [a] -> [String] -> IO (Maybe (Rules ()))
runWithArgs rules _flags args = pure $ Just $
case args of
[] -> rules
(a:_) -> want [a] >> withoutActions rules
-- shakeArgsWith :: ShakeOptions -> [OptDescr (Either String a)] -> ([a] -> [String] -> IO (Maybe (Rules ()))) -> IO ()
shakeArgsWith opts [] (runWithArgs rules)
-- Convert numbered man page names to manual names.
-- hledger.1 -> hledger, hledger_journal.5 -> hledger_journal