imp: --tldr: show the source if 'tldr' is not installed
This commit is contained in:
parent
152b20413c
commit
29567a3b29
@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE TemplateHaskell, OverloadedStrings, PackageImports #-}
|
{-# LANGUAGE TemplateHaskell, OverloadedStrings, PackageImports, ScopedTypeVariables #-}
|
||||||
{-|
|
{-|
|
||||||
|
|
||||||
Embedded documentation files in various formats, and helpers for viewing them.
|
Embedded documentation files in various formats, and helpers for viewing them.
|
||||||
@ -16,6 +16,7 @@ module Hledger.Cli.DocFiles (
|
|||||||
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Control.Exception
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import qualified Data.ByteString.Char8 as BC
|
import qualified Data.ByteString.Char8 as BC
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
@ -146,11 +147,15 @@ tldr name = lookup name tldrs
|
|||||||
-- | Display one of the hledger tldr pages, using "tldr".
|
-- | Display one of the hledger tldr pages, using "tldr".
|
||||||
runTldrForPage :: TldrPage -> IO ()
|
runTldrForPage :: TldrPage -> IO ()
|
||||||
runTldrForPage name =
|
runTldrForPage name =
|
||||||
|
let tldrprog = "tldr" in
|
||||||
case tldr name of
|
case tldr name of
|
||||||
Nothing -> error' $ "sorry, there's no " <> name <> " tldr page yet"
|
Nothing -> error' $ "sorry, there's no " <> name <> " tldr page yet"
|
||||||
Just b -> do
|
Just b -> (do
|
||||||
withSystemTempFile (name++".md") $ \f h -> do
|
withSystemTempFile (name++".md") $ \f h -> do
|
||||||
BC.hPutStrLn h b
|
BC.hPutStrLn h b
|
||||||
hClose h
|
hClose h
|
||||||
callCommand $ dbg1 "tldr command" $ unwords ["tldr", "-r", f]
|
callCommand $ dbg1 "tldr command" $ unwords [tldrprog, "-r", f]
|
||||||
|
) `catch` (\(_e::IOException) -> do
|
||||||
|
hPutStrLn stderr $ "Could not run " <> tldrprog <> ", using fallback viewer:\n"
|
||||||
|
BC.putStrLn b
|
||||||
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user