;tools: Shake cmddocs: ignore failures when running hledger -h
Eg if it's not yet built/buildable, carry on without updating the flag docs.
This commit is contained in:
parent
91d5308783
commit
8e0326b521
21
Shake.hs
21
Shake.hs
@ -598,27 +598,38 @@ main = do
|
|||||||
need commandmdsnew
|
need commandmdsnew
|
||||||
when commit $ commitIfChanged ";doc: update command flag docs" commandmds
|
when commit $ commitIfChanged ";doc: update command flag docs" commandmds
|
||||||
|
|
||||||
-- hledger/Hledger/Cli/Commands/CMD.md.new: updates the command-specific flags help
|
-- hledger/Hledger/Cli/Commands/CMD.md.new: a phony target that updates the flags doc
|
||||||
-- within hledger/Hledger/Cli/Commands/CMD.md. Runs "stack exec -- hledger CMD -h".
|
-- within hledger/Hledger/Cli/Commands/CMD.md. Runs "stack run -- hledger CMD -h" to get the latest.
|
||||||
|
-- If that fails, a warning is printed and it carries on, keeping the old flags doc.
|
||||||
phonys $ \out ->
|
phonys $ \out ->
|
||||||
if not $ ".md.new" `isSuffixOf` out
|
if not $ "hledger/Hledger/Cli/Commands/" `isPrefixOf` out && ".md.new" `isSuffixOf` out
|
||||||
then Nothing
|
then Nothing
|
||||||
else Just $ do
|
else Just $ do
|
||||||
let src = dropExtension out
|
let src = dropExtension out
|
||||||
need [src]
|
need [src]
|
||||||
liftIO $ putStrLn ("running hledger, updating flags in " <> src)
|
|
||||||
srcls <- fmap lines $ liftIO $ readFileStrictly src
|
srcls <- fmap lines $ liftIO $ readFileStrictly src
|
||||||
let
|
let
|
||||||
(pre,rest) = break (=="```flags") srcls
|
(pre,rest) = break (=="```flags") srcls
|
||||||
(_,post) = span (/="```") rest
|
(_,post) = span (/="```") rest
|
||||||
let cmdname = map toLower $ takeBaseName src
|
let cmdname = map toLower $ takeBaseName src
|
||||||
cmdhelp <- lines . fromStdout <$> (cmd Shell $ "stack exec -- hledger -h " <> cmdname :: Action (Stdout String))
|
do
|
||||||
|
let shellcmd = "stack exec -- hledger -h " <> cmdname
|
||||||
|
liftIO $ putStrLn ("running " <> shellcmd <> " to update flags in " <> src)
|
||||||
|
cmdhelp <- lines . fromStdout <$> (cmd Shell shellcmd :: Action (Stdout String))
|
||||||
let
|
let
|
||||||
cmdflagshelp = takeWhile (not.null) $ dropWhile (/="Flags:") cmdhelp
|
cmdflagshelp = takeWhile (not.null) $ dropWhile (/="Flags:") cmdhelp
|
||||||
cmdflagshelp'
|
cmdflagshelp'
|
||||||
| null cmdflagshelp = ["Flags:","no command-specific flags"]
|
| null cmdflagshelp = ["Flags:","no command-specific flags"]
|
||||||
| otherwise = cmdflagshelp
|
| otherwise = cmdflagshelp
|
||||||
liftIO $ writeFile src $ unlines $ concat [pre, ["```flags"], cmdflagshelp', post]
|
liftIO $ writeFile src $ unlines $ concat [pre, ["```flags"], cmdflagshelp', post]
|
||||||
|
-- This is supposed to print the error but otherwise ignore it, making this action a no-op,
|
||||||
|
-- in case hledger is not yet built/runnable.
|
||||||
|
`actionCatch` \(e::C.IOException) -> return ()
|
||||||
|
-- XXX should somehow control the output and elide the verbose "not found on path" errors
|
||||||
|
-- let elide err
|
||||||
|
-- | "path: [" `isInfixOf` err = takeWhile (/='[') err <> "..."
|
||||||
|
-- | otherwise = err
|
||||||
|
-- in \(e::C.IOException) -> liftIO $ hPutStrLn stderr $ elide $ show e -- not used
|
||||||
|
|
||||||
-- Regenerate Hledger/Cli/Commands/*.txt, rendering the corresponding .md files as plain text.
|
-- Regenerate Hledger/Cli/Commands/*.txt, rendering the corresponding .md files as plain text.
|
||||||
-- Also updates cmddocs first.
|
-- Also updates cmddocs first.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user