imp:demo: show a better error message if asciinema is not installed
This commit is contained in:
parent
3952d4e611
commit
57b1e18757
@ -55,6 +55,8 @@ import System.Console.CmdArgs.Explicit (flagReq)
|
|||||||
|
|
||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Cli.CliOptions
|
import Hledger.Cli.CliOptions
|
||||||
|
import System.Directory (findExecutable)
|
||||||
|
import Control.Monad (when)
|
||||||
|
|
||||||
demos :: [Demo]
|
demos :: [Demo]
|
||||||
demos = map readDemo [
|
demos = map readDemo [
|
||||||
@ -103,6 +105,9 @@ demo CliOpts{rawopts_=rawopts, reportspec_=ReportSpec{_rsQuery=_query}} _j = do
|
|||||||
,listDemos
|
,listDemos
|
||||||
]
|
]
|
||||||
Just (Demo t c) -> do
|
Just (Demo t c) -> do
|
||||||
|
-- check if asciinema is installed, first
|
||||||
|
masciinema <- findExecutable "asciinema"
|
||||||
|
when (isNothing masciinema) $ error' "Could not find 'asciinema'; please install that first."
|
||||||
let
|
let
|
||||||
-- try to preserve the original pauses a bit while also moving things along
|
-- try to preserve the original pauses a bit while also moving things along
|
||||||
defidlelimit = 10
|
defidlelimit = 10
|
||||||
@ -149,8 +154,8 @@ listDemos = unlines $
|
|||||||
|
|
||||||
-- | Run asciinema play with the given speed and idle limit, passing the given content to its stdin.
|
-- | Run asciinema play with the given speed and idle limit, passing the given content to its stdin.
|
||||||
runAsciinemaPlay :: Float -> Float -> ByteString -> [String] -> IO ()
|
runAsciinemaPlay :: Float -> Float -> ByteString -> [String] -> IO ()
|
||||||
runAsciinemaPlay speed idlelimit content args =
|
runAsciinemaPlay speed idlelimit content args = do
|
||||||
-- XXX try piping to stdin also
|
-- XXX try piping to stdin also
|
||||||
withSystemTempFile "hledger-cast" $ \f h -> do
|
withSystemTempFile "hledger-cast" $ \f h -> do
|
||||||
-- don't add an extra newline here, it breaks asciinema 2.3.0 (#2094).
|
-- don't add an extra newline here, it breaks asciinema 2.3.0 (#2094).
|
||||||
-- XXX we could try harder and strip excess newlines/carriage returns+linefeeds here
|
-- XXX we could try harder and strip excess newlines/carriage returns+linefeeds here
|
||||||
@ -169,8 +174,7 @@ runAsciinemaPlay speed idlelimit content args =
|
|||||||
,"Running asciinema failed. Trying 'asciinema --version':"
|
,"Running asciinema failed. Trying 'asciinema --version':"
|
||||||
]
|
]
|
||||||
callProcess "asciinema" ["--version"]
|
callProcess "asciinema" ["--version"]
|
||||||
`catchIOError` \_ ->
|
`catchIOError` \_ -> error' "This also failed."
|
||||||
error' "This also failed. Check that asciinema is installed in your PATH."
|
|
||||||
where
|
where
|
||||||
showwithouttrailingzero = dropWhileEnd (=='.') . dropWhileEnd (=='0') . show
|
showwithouttrailingzero = dropWhileEnd (=='.') . dropWhileEnd (=='0') . show
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user