;shake: simplify argument handling, fix setversion
This commit is contained in:
		
							parent
							
								
									306975e6ac
								
							
						
					
					
						commit
						00e12c626c
					
				
							
								
								
									
										46
									
								
								Shake.hs
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								Shake.hs
									
									
									
									
									
								
							| @ -109,7 +109,7 @@ towebmd = "-t markdown-smart-fenced_divs-fenced_code_attributes-simple_tables-mu | |||||||
| 
 | 
 | ||||||
| main = do | main = do | ||||||
| 
 | 
 | ||||||
|   -- 1. gather some IO values used by rules |   -- Gather some IO values used by rules. | ||||||
| 
 | 
 | ||||||
|   -- hledger manual also includes the markdown files from here: |   -- hledger manual also includes the markdown files from here: | ||||||
|   let commandsdir = "hledger/Hledger/Cli/Commands" |   let commandsdir = "hledger/Hledger/Cli/Commands" | ||||||
| @ -121,16 +121,25 @@ main = do | |||||||
|   let sitedir = "site" |   let sitedir = "site" | ||||||
|   pages <- map takeBaseName . filter (".md" `isSuffixOf`) <$> S.getDirectoryContents sitedir |   pages <- map takeBaseName . filter (".md" `isSuffixOf`) <$> S.getDirectoryContents sitedir | ||||||
| 
 | 
 | ||||||
|   -- The rule that we run can make use of command line opts/args if it wants. |   -- Run the shake rule selected by the first command line argument. | ||||||
|   -- We distinguish them by the dash, so option arguments should be adjacent to their flag. |   -- Other arguments and some custom flags are set aside for the rule | ||||||
|   (opts, args') <- partition ("-" `isPrefixOf`) <$> getArgs |   -- to use if it wants. | ||||||
|   let (target, args) = splitAt 1 args' |  | ||||||
| 
 |  | ||||||
|   -- 2. define the shake rules |  | ||||||
| 
 | 
 | ||||||
|  |   -- Option arguments should be kept adjacent to their flag or this will go wrong. | ||||||
|  |   (opts, args) <- partition ("-" `isPrefixOf`) <$> getArgs | ||||||
|   let |   let | ||||||
|     rules :: Rules () |     ruleoptnames = [ "--commit" ] | ||||||
|     rules = do |     (ruleopts, shakeopts) = partition (`elem` ruleoptnames) opts | ||||||
|  |     (shakearg, ruleargs) = splitAt 1 args | ||||||
|  |     shakeargs = shakeopts ++ shakearg | ||||||
|  |   -- print (opts,args,shakeopts,shakearg,shakeargs,ruleopts,ruleargs) | ||||||
|  |   withArgs shakeargs $ shakeArgs shakeOptions{ | ||||||
|  |     shakeVerbosity=Quiet | ||||||
|  |     -- ,shakeReport=[".shake.html"] | ||||||
|  |     } | ||||||
|  |     $ do | ||||||
|  |     | ||||||
|  |   -- The rules. | ||||||
|    |    | ||||||
|       want ["help"] |       want ["help"] | ||||||
| 
 | 
 | ||||||
| @ -499,7 +508,7 @@ main = do | |||||||
|       phony "setversion" $ do |       phony "setversion" $ do | ||||||
|         let |         let | ||||||
|           (mver, dirargs) = (headMay ver', drop 1 ver' ++ dirs') |           (mver, dirargs) = (headMay ver', drop 1 ver' ++ dirs') | ||||||
|             where (ver',dirs') = span isVersion args |             where (ver',dirs') = span isVersion ruleargs | ||||||
|           (specifieddirs, specifiedpkgs) = |           (specifieddirs, specifiedpkgs) = | ||||||
|             case dirargs of [] -> (pkgandprojdirs, pkgdirs) |             case dirargs of [] -> (pkgandprojdirs, pkgdirs) | ||||||
|                             ds -> (ds, ds) |                             ds -> (ds, ds) | ||||||
| @ -619,23 +628,6 @@ main = do | |||||||
|         putNormal "Cleaning shake build cache" |         putNormal "Cleaning shake build cache" | ||||||
|         removeFilesAfter ".shake" ["//*"] |         removeFilesAfter ".shake" ["//*"] | ||||||
| 
 | 
 | ||||||
|   -- 3. run the shake rule selected by the first command line argument, |  | ||||||
|   -- leaving the other args for the rule to use |  | ||||||
| 
 |  | ||||||
|   let |  | ||||||
|     shakeopts = 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 shakeopts [] (runWithArgs rules) |  | ||||||
|    |    | ||||||
| 
 | 
 | ||||||
| -- Convert numbered man page names to manual names. | -- Convert numbered man page names to manual names. | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user