feat: hledger's tldr pages are now built in, accessible via --tldr
And a few cleanups/fixes related to flag processing. The help flags are now listed in order of precedence.
This commit is contained in:
parent
4a57403684
commit
c5f8444627
@ -76,6 +76,7 @@ hledgerUiMain = withGhcDebug' $ withProgName "hledger-ui.log" $ do -- force Hle
|
|||||||
|
|
||||||
case True of
|
case True of
|
||||||
_ | boolopt "help" rawopts -> pager $ showModeUsage uimode ++ "\n"
|
_ | boolopt "help" rawopts -> pager $ showModeUsage uimode ++ "\n"
|
||||||
|
_ | boolopt "tldr" rawopts -> runTldrForPage "hledger-ui"
|
||||||
_ | boolopt "info" rawopts -> runInfoForTopic "hledger-ui" Nothing
|
_ | boolopt "info" rawopts -> runInfoForTopic "hledger-ui" Nothing
|
||||||
_ | boolopt "man" rawopts -> runManForTopic "hledger-ui" Nothing
|
_ | boolopt "man" rawopts -> runManForTopic "hledger-ui" Nothing
|
||||||
_ | boolopt "version" rawopts -> putStrLn prognameandversion
|
_ | boolopt "version" rawopts -> putStrLn prognameandversion
|
||||||
|
|||||||
@ -89,10 +89,11 @@ uimode =
|
|||||||
|
|
||||||
uihelpflags :: [Flag RawOpts]
|
uihelpflags :: [Flag RawOpts]
|
||||||
uihelpflags = [
|
uihelpflags = [
|
||||||
flagNone ["version"] (setboolopt "version") "show version information"
|
flagNone ["help","h"] (setboolopt "help") "show command line help"
|
||||||
,flagNone ["help","h"] (setboolopt "help") "show command line help"
|
,flagNone ["tldr"] (setboolopt "tldr") "show command examples with tldr"
|
||||||
,flagNone ["info"] (setboolopt "info") "show the hledger-ui manual with info"
|
,flagNone ["info"] (setboolopt "info") "show the hledger-ui manual with info"
|
||||||
,flagNone ["man"] (setboolopt "man") "show the hledger-ui manual with man"
|
,flagNone ["man"] (setboolopt "man") "show the hledger-ui manual with man"
|
||||||
|
,flagNone ["version"] (setboolopt "version") "show version information"
|
||||||
]
|
]
|
||||||
|
|
||||||
-- hledger-ui options, used in hledger-ui and above
|
-- hledger-ui options, used in hledger-ui and above
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import Network.Wai.Handler.Warp (runSettings, runSettingsSocket, defaultSettings
|
|||||||
import Network.Wai.Handler.Launch (runHostPortFullUrl)
|
import Network.Wai.Handler.Launch (runHostPortFullUrl)
|
||||||
import System.Directory (removeFile)
|
import System.Directory (removeFile)
|
||||||
import System.Environment ( getArgs, withArgs )
|
import System.Environment ( getArgs, withArgs )
|
||||||
import System.Exit (exitSuccess, exitFailure)
|
import System.Exit (exitFailure)
|
||||||
import System.IO (hFlush, stdout)
|
import System.IO (hFlush, stdout)
|
||||||
import System.PosixCompat.Files (getFileStatus, isSocket)
|
import System.PosixCompat.Files (getFileStatus, isSocket)
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
@ -56,6 +56,7 @@ hledgerWebMain = withGhcDebug' $ do
|
|||||||
when (debug_ > 0) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show wopts)
|
when (debug_ > 0) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show wopts)
|
||||||
if
|
if
|
||||||
| boolopt "help" rawopts_ -> pager $ showModeUsage webmode ++ "\n"
|
| boolopt "help" rawopts_ -> pager $ showModeUsage webmode ++ "\n"
|
||||||
|
| boolopt "tldr" rawopts_ -> runTldrForPage "hledger-web"
|
||||||
| boolopt "info" rawopts_ -> runInfoForTopic "hledger-web" Nothing
|
| boolopt "info" rawopts_ -> runInfoForTopic "hledger-web" Nothing
|
||||||
| boolopt "man" rawopts_ -> runManForTopic "hledger-web" Nothing
|
| boolopt "man" rawopts_ -> runManForTopic "hledger-web" Nothing
|
||||||
| boolopt "version" rawopts_ -> putStrLn prognameandversion
|
| boolopt "version" rawopts_ -> putStrLn prognameandversion
|
||||||
|
|||||||
@ -120,10 +120,11 @@ webmode =
|
|||||||
|
|
||||||
webhelpflags :: [Flag RawOpts]
|
webhelpflags :: [Flag RawOpts]
|
||||||
webhelpflags = [
|
webhelpflags = [
|
||||||
flagNone ["version"] (setboolopt "version") "show version information"
|
flagNone ["help","h"] (setboolopt "help") "show command line help"
|
||||||
,flagNone ["help","h"] (setboolopt "help") "show command line help"
|
,flagNone ["tldr"] (setboolopt "tldr") "show command examples with tldr"
|
||||||
,flagNone ["info"] (setboolopt "info") "show the hledger-web manual with info"
|
,flagNone ["info"] (setboolopt "info") "show the hledger-web manual with info"
|
||||||
,flagNone ["man"] (setboolopt "man") "show the hledger-web manual with man"
|
,flagNone ["man"] (setboolopt "man") "show the hledger-web manual with man"
|
||||||
|
,flagNone ["version"] (setboolopt "version") "show version information"
|
||||||
]
|
]
|
||||||
|
|
||||||
-- hledger-web options, used in hledger-web and above
|
-- hledger-web options, used in hledger-web and above
|
||||||
|
|||||||
@ -188,23 +188,25 @@ main = withGhcDebug' $ do
|
|||||||
opts' <- argsToCliOpts args addons
|
opts' <- argsToCliOpts args addons
|
||||||
let opts = opts'{progstarttime_=starttime}
|
let opts = opts'{progstarttime_=starttime}
|
||||||
|
|
||||||
-- select an action and run it.
|
-- select an action and prepare to run it
|
||||||
let
|
let
|
||||||
cmd = command_ opts -- the full matched internal or external command name, if any
|
cmd = command_ opts -- the full matched internal or external command name, if any
|
||||||
isInternalCommand = cmd `elem` builtinCommandNames -- not (null cmd) && not (cmd `elem` addons)
|
isInternalCommand = cmd `elem` builtinCommandNames -- not (null cmd) && not (cmd `elem` addons)
|
||||||
isExternalCommand = not (null cmd) && cmd `elem` addons -- probably
|
isExternalCommand = not (null cmd) && cmd `elem` addons -- probably
|
||||||
isBadCommand = not (null rawcmd) && null cmd
|
isBadCommand = not (null rawcmd) && null cmd
|
||||||
hasVersion = ("--version" `elem`)
|
printUsage = pager $ showModeUsage (mainmode addons) ++ "\n"
|
||||||
printUsage = pager $ showModeUsage (mainmode addons) ++ "\n"
|
badCommandError = error' ("command "++rawcmd++" is not recognized, run with no command to see a list") >> exitFailure -- PARTIAL:
|
||||||
badCommandError = error' ("command "++rawcmd++" is not recognized, run with no command to see a list") >> exitFailure -- PARTIAL:
|
helpFlag = boolopt "help" $ rawopts_ opts
|
||||||
hasHelpFlag args1 = any (`elem` args1) ["-h","--help"]
|
tldrFlag = boolopt "tldr" $ rawopts_ opts
|
||||||
hasManFlag args1 = (`elem` args1) "--man"
|
infoFlag = boolopt "info" $ rawopts_ opts
|
||||||
hasInfoFlag args1 = (`elem` args1) "--info"
|
manFlag = boolopt "man" $ rawopts_ opts
|
||||||
|
versionFlag = boolopt "version" $ rawopts_ opts
|
||||||
f `orShowHelp` mode1
|
f `orShowHelp` mode1
|
||||||
| hasHelpFlag args = pager $ showModeUsage mode1 ++ "\n"
|
| helpFlag = pager $ showModeUsage mode1 ++ "\n"
|
||||||
| hasInfoFlag args = runInfoForTopic "hledger" (headMay $ modeNames mode1)
|
| tldrFlag = runTldrForPage $ maybe "hledger" (("hledger-"<>)) $ headMay $ modeNames mode1
|
||||||
| hasManFlag args = runManForTopic "hledger" (headMay $ modeNames mode1)
|
| infoFlag = runInfoForTopic "hledger" (headMay $ modeNames mode1)
|
||||||
| otherwise = f
|
| manFlag = runManForTopic "hledger" (headMay $ modeNames mode1)
|
||||||
|
| otherwise = f
|
||||||
-- where
|
-- where
|
||||||
-- lastdocflag
|
-- lastdocflag
|
||||||
dbgIO "processed opts" opts
|
dbgIO "processed opts" opts
|
||||||
@ -217,29 +219,26 @@ main = withGhcDebug' $ do
|
|||||||
dbgIO "interval from opts" (interval_ . _rsReportOpts $ reportspec_ opts)
|
dbgIO "interval from opts" (interval_ . _rsReportOpts $ reportspec_ opts)
|
||||||
dbgIO "query from opts & args" (_rsQuery $ reportspec_ opts)
|
dbgIO "query from opts & args" (_rsQuery $ reportspec_ opts)
|
||||||
let
|
let
|
||||||
journallesserror = error $ cmd++" tried to read the journal but is not supposed to"
|
|
||||||
runHledgerCommand
|
runHledgerCommand
|
||||||
-- high priority flags and situations. -h, then --help, then --info are highest priority.
|
-- high priority flags and situations. -h, then --help, then --tldr, then --info, then --man are highest priority.
|
||||||
| isNullCommand && hasHelpFlag args = dbgIO "" "-h/--help with no command, showing general help" >> printUsage
|
| isNullCommand && helpFlag = dbgIO "" "-h/--help with no command, showing general help" >> printUsage
|
||||||
| isNullCommand && hasInfoFlag args = dbgIO "" "--info with no command, showing general info manual" >> runInfoForTopic "hledger" Nothing
|
| isNullCommand && tldrFlag = dbgIO "" "--tldr with no command, showing general tldr page" >> runTldrForPage "hledger"
|
||||||
| isNullCommand && hasManFlag args = dbgIO "" "--man with no command, showing general man page" >> runManForTopic "hledger" Nothing
|
| isNullCommand && infoFlag = dbgIO "" "--info with no command, showing general info manual" >> runInfoForTopic "hledger" Nothing
|
||||||
| not (isExternalCommand || hasHelpFlag args || hasInfoFlag args || hasManFlag args)
|
| isNullCommand && manFlag = dbgIO "" "--man with no command, showing general man page" >> runManForTopic "hledger" Nothing
|
||||||
&& (hasVersion args) -- || (hasVersion argsaftercmd && isInternalCommand))
|
| versionFlag && not (isExternalCommand || helpFlag || tldrFlag || infoFlag || manFlag) = putStrLn prognameandversion
|
||||||
= putStrLn prognameandversion
|
| isNullCommand = dbgIO "" "no command, showing commands list" >> printCommandsList prognameandversion addons
|
||||||
-- \| (null externalcmd) && boolopt "binary-filename" rawopts = putStrLn $ binaryfilename progname
|
| isBadCommand = badCommandError
|
||||||
-- \| "--browse-args" `elem` args = System.Console.CmdArgs.Helper.execute "cmdargs-browser" mainmode' args >>= (putStr . show)
|
|
||||||
| isNullCommand = dbgIO "" "no command, showing commands list" >> printCommandsList prognameandversion addons
|
|
||||||
| isBadCommand = badCommandError
|
|
||||||
|
|
||||||
-- builtin commands
|
-- builtin commands
|
||||||
| Just (cmdmode, cmdaction) <- findBuiltinCommand cmd =
|
| Just (cmdmode, cmdaction) <- findBuiltinCommand cmd =
|
||||||
(case True of
|
(case True of
|
||||||
-- these commands should not require or read the journal
|
-- these commands should not require or read the journal
|
||||||
_ | cmd `elem` ["demo","help","test"] -> cmdaction opts journallesserror
|
_ | cmd `elem` ["demo","help","test"] ->
|
||||||
|
cmdaction opts $ error' $ cmd++" tried to read the journal but is not supposed to"
|
||||||
-- these commands should create the journal if missing
|
-- these commands should create the journal if missing
|
||||||
_ | cmd `elem` ["add","import"] -> do
|
_ | cmd `elem` ["add","import"] -> do
|
||||||
ensureJournalFileExists . NE.head =<< journalFilePathFromOpts opts
|
ensureJournalFileExists . NE.head =<< journalFilePathFromOpts opts
|
||||||
withJournalDo opts (cmdaction opts)
|
withJournalDo opts (cmdaction opts)
|
||||||
-- other commands read the journal and should fail if it's missing
|
-- other commands read the journal and should fail if it's missing
|
||||||
_ -> withJournalDo opts (cmdaction opts)
|
_ -> withJournalDo opts (cmdaction opts)
|
||||||
)
|
)
|
||||||
@ -260,6 +259,7 @@ main = withGhcDebug' $ do
|
|||||||
-- shouldn't reach here
|
-- shouldn't reach here
|
||||||
| otherwise = usageError ("could not understand the arguments "++show args) >> exitFailure
|
| otherwise = usageError ("could not understand the arguments "++show args) >> exitFailure
|
||||||
|
|
||||||
|
-- do it
|
||||||
runHledgerCommand
|
runHledgerCommand
|
||||||
|
|
||||||
when (ghcDebugMode == GDPauseAtEnd) $ ghcDebugPause'
|
when (ghcDebugMode == GDPauseAtEnd) $ ghcDebugPause'
|
||||||
@ -317,8 +317,11 @@ isValue "-" = True
|
|||||||
isValue ('-':_) = False
|
isValue ('-':_) = False
|
||||||
isValue _ = True
|
isValue _ = True
|
||||||
|
|
||||||
flagstomove = inputflags ++ reportflags ++ helpflags
|
flagstomove = inputflags ++ reportflags ++ clihelpflags
|
||||||
noargflagstomove = concatMap flagNames $ filter ((==FlagNone).flagInfo) flagstomove
|
noargflagstomove = concatMap flagNames (filter ((==FlagNone).flagInfo) flagstomove)
|
||||||
|
-- silly special case: if someone is abbreviating --tldr, make sure it works right when written before COMMAND
|
||||||
|
-- (not needed for --info, --man, --version since their abbreviations are ambiguous)
|
||||||
|
++ ["tl", "tld"]
|
||||||
reqargflagstomove = -- filter (/= "debug") $
|
reqargflagstomove = -- filter (/= "debug") $
|
||||||
concatMap flagNames $ filter ((==FlagReq ).flagInfo) flagstomove
|
concatMap flagNames $ filter ((==FlagReq ).flagInfo) flagstomove
|
||||||
optargflagstomove = concatMap flagNames $ filter (isFlagOpt .flagInfo) flagstomove
|
optargflagstomove = concatMap flagNames $ filter (isFlagOpt .flagInfo) flagstomove
|
||||||
|
|||||||
@ -240,10 +240,11 @@ reportflags = [
|
|||||||
|
|
||||||
clihelpflags :: [Flag RawOpts]
|
clihelpflags :: [Flag RawOpts]
|
||||||
clihelpflags = [
|
clihelpflags = [
|
||||||
flagNone ["version"] (setboolopt "version") "show version information"
|
flagNone ["help","h"] (setboolopt "help") "show command line help"
|
||||||
,flagNone ["help","h"] (setboolopt "help") "show command-line help for hledger [or COMMAND]"
|
,flagNone ["tldr"] (setboolopt "tldr") "show command examples with tldr"
|
||||||
,flagNone ["info"] (setboolopt "info") "show the hledger manual [for COMMAND] with info"
|
,flagNone ["info"] (setboolopt "info") "show the hledger manual with info"
|
||||||
,flagNone ["man"] (setboolopt "man") "show the hledger manual [for COMMAND] with man"
|
,flagNone ["man"] (setboolopt "man") "show the hledger manual with man"
|
||||||
|
,flagNone ["version"] (setboolopt "version") "show version information"
|
||||||
]
|
]
|
||||||
-- XXX why are these duplicated in defCommandMode below ?
|
-- XXX why are these duplicated in defCommandMode below ?
|
||||||
|
|
||||||
|
|||||||
@ -8,15 +8,11 @@ Embedded documentation files in various formats, and helpers for viewing them.
|
|||||||
module Hledger.Cli.DocFiles (
|
module Hledger.Cli.DocFiles (
|
||||||
|
|
||||||
Topic
|
Topic
|
||||||
-- ,toolDocs
|
|
||||||
-- ,toolDocNames
|
|
||||||
-- ,toolDocMan
|
|
||||||
-- ,toolDocTxt
|
|
||||||
-- ,toolDocInfo
|
|
||||||
,printHelpForTopic
|
,printHelpForTopic
|
||||||
,runManForTopic
|
,runManForTopic
|
||||||
,runInfoForTopic
|
,runInfoForTopic
|
||||||
,runPagerForTopic
|
,runPagerForTopic
|
||||||
|
,runTldrForPage
|
||||||
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@ -28,7 +24,7 @@ import System.IO
|
|||||||
import System.IO.Temp
|
import System.IO.Temp
|
||||||
import System.Process
|
import System.Process
|
||||||
|
|
||||||
import Hledger.Utils (first3, second3, third3, embedFileRelative)
|
import Hledger.Utils (first3, second3, third3, embedFileRelative, error')
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
import System.Environment (lookupEnv)
|
import System.Environment (lookupEnv)
|
||||||
import Hledger.Utils.Debug
|
import Hledger.Utils.Debug
|
||||||
@ -39,11 +35,30 @@ type Tool = String
|
|||||||
-- Any heading in the hledger user manual (and perhaps later the hledger-ui/hledger-web manuals).
|
-- Any heading in the hledger user manual (and perhaps later the hledger-ui/hledger-web manuals).
|
||||||
type Topic = String
|
type Topic = String
|
||||||
|
|
||||||
|
-- Any name of a hledger tldr page (hledger, hledger-ui, hledger-print etc.)
|
||||||
|
type TldrPage = String
|
||||||
|
|
||||||
|
-- | All hledger-related pages from the tldr-pages project.
|
||||||
|
-- All are symlinked into the hledger package directory to allow embeddeding.
|
||||||
|
tldrs :: [(TldrPage, ByteString)]
|
||||||
|
tldrs = [
|
||||||
|
("hledger-accounts", $(embedFileRelative "embeddedfiles/hledger-accounts.md"))
|
||||||
|
,("hledger-add", $(embedFileRelative "embeddedfiles/hledger-add.md"))
|
||||||
|
,("hledger-aregister", $(embedFileRelative "embeddedfiles/hledger-aregister.md"))
|
||||||
|
,("hledger-balance", $(embedFileRelative "embeddedfiles/hledger-balance.md"))
|
||||||
|
,("hledger-balancesheet", $(embedFileRelative "embeddedfiles/hledger-balancesheet.md"))
|
||||||
|
,("hledger-import", $(embedFileRelative "embeddedfiles/hledger-import.md"))
|
||||||
|
,("hledger-incomestatement", $(embedFileRelative "embeddedfiles/hledger-incomestatement.md"))
|
||||||
|
,("hledger-print", $(embedFileRelative "embeddedfiles/hledger-print.md"))
|
||||||
|
,("hledger-ui", $(embedFileRelative "embeddedfiles/hledger-ui.md"))
|
||||||
|
,("hledger-web", $(embedFileRelative "embeddedfiles/hledger-web.md"))
|
||||||
|
,("hledger", $(embedFileRelative "embeddedfiles/hledger.md"))
|
||||||
|
]
|
||||||
|
|
||||||
-- | The main hledger manuals as source for man, info and as plain text.
|
-- | The main hledger manuals as source for man, info and as plain text.
|
||||||
-- Only files under the current package directory can be embedded,
|
-- All are symlinked into the hledger package directory to allow embeddeding.
|
||||||
-- so some of these are symlinked from the other package directories.
|
manuals :: [(Tool, (ByteString, ByteString, ByteString))]
|
||||||
toolDocs :: [(Tool, (ByteString, ByteString, ByteString))]
|
manuals = [
|
||||||
toolDocs = [
|
|
||||||
("hledger",
|
("hledger",
|
||||||
($(embedFileRelative "embeddedfiles/hledger.1")
|
($(embedFileRelative "embeddedfiles/hledger.1")
|
||||||
,$(embedFileRelative "embeddedfiles/hledger.txt")
|
,$(embedFileRelative "embeddedfiles/hledger.txt")
|
||||||
@ -61,29 +76,22 @@ toolDocs = [
|
|||||||
))
|
))
|
||||||
]
|
]
|
||||||
|
|
||||||
-- toolNames :: [Tool]
|
|
||||||
-- toolNames = map fst toolDocs
|
|
||||||
|
|
||||||
-- | Get the manual as plain text for this tool, or a not found message.
|
-- | Get the manual as plain text for this tool, or a not found message.
|
||||||
toolDocTxt :: Tool -> ByteString
|
manualTxt :: Tool -> ByteString
|
||||||
toolDocTxt name =
|
manualTxt name = maybe (fromString $ "No text manual found for tool: "++name) second3 $ lookup name manuals
|
||||||
maybe (fromString $ "No text manual found for tool: "++name) second3 $ lookup name toolDocs
|
|
||||||
|
|
||||||
-- | Get the manual as man source (nroff) for this tool, or a not found message.
|
-- | Get the manual as man source (nroff) for this tool, or a not found message.
|
||||||
toolDocMan :: Tool -> ByteString
|
manualMan :: Tool -> ByteString
|
||||||
toolDocMan name =
|
manualMan name = maybe (fromString $ "No man page found for tool: "++name) first3 $ lookup name manuals
|
||||||
maybe (fromString $ "No man page found for tool: "++name) first3 $ lookup name toolDocs
|
|
||||||
|
|
||||||
-- | Get the manual as info source (texinfo) for this tool, or a not found message.
|
-- | Get the manual as info source (texinfo) for this tool, or a not found message.
|
||||||
toolDocInfo :: Tool -> ByteString
|
manualInfo :: Tool -> ByteString
|
||||||
toolDocInfo name =
|
manualInfo name = maybe (fromString $ "No info manual found for tool: "++name) third3 $ lookup name manuals
|
||||||
maybe (fromString $ "No info manual found for tool: "++name) third3 $ lookup name toolDocs
|
|
||||||
|
|
||||||
-- | Print plain text help for this tool.
|
-- | Print plain text help for this tool.
|
||||||
-- Takes an optional topic argument for convenience but it is currently ignored.
|
-- Takes an optional topic argument for convenience but it is currently ignored.
|
||||||
printHelpForTopic :: Tool -> Maybe Topic -> IO ()
|
printHelpForTopic :: Tool -> Maybe Topic -> IO ()
|
||||||
printHelpForTopic tool _mtopic =
|
printHelpForTopic tool _mtopic = BC.putStr (manualTxt tool)
|
||||||
BC.putStr (toolDocTxt tool)
|
|
||||||
|
|
||||||
-- | Display an info manual for this topic, opened at the given topic if provided,
|
-- | Display an info manual for this topic, opened at the given topic if provided,
|
||||||
-- using the "info" executable in $PATH.
|
-- using the "info" executable in $PATH.
|
||||||
@ -91,7 +99,7 @@ printHelpForTopic tool _mtopic =
|
|||||||
runInfoForTopic :: Tool -> Maybe Topic -> IO ()
|
runInfoForTopic :: Tool -> Maybe Topic -> IO ()
|
||||||
runInfoForTopic tool mtopic =
|
runInfoForTopic tool mtopic =
|
||||||
withSystemTempFile ("hledger-"++tool++".info") $ \f h -> do
|
withSystemTempFile ("hledger-"++tool++".info") $ \f h -> do
|
||||||
BC.hPutStrLn h $ toolDocInfo tool
|
BC.hPutStrLn h $ manualInfo tool
|
||||||
hClose h
|
hClose h
|
||||||
callCommand $ dbg1 "info command" $
|
callCommand $ dbg1 "info command" $
|
||||||
"info -f " ++ f ++ maybe "" (printf " -n '%s'") mtopic
|
"info -f " ++ f ++ maybe "" (printf " -n '%s'") mtopic
|
||||||
@ -104,7 +112,7 @@ less = "less -s -i --use-backslash"
|
|||||||
runPagerForTopic :: Tool -> Maybe Topic -> IO ()
|
runPagerForTopic :: Tool -> Maybe Topic -> IO ()
|
||||||
runPagerForTopic tool mtopic = do
|
runPagerForTopic tool mtopic = do
|
||||||
withSystemTempFile ("hledger-"++tool++".txt") $ \f h -> do
|
withSystemTempFile ("hledger-"++tool++".txt") $ \f h -> do
|
||||||
BC.hPutStrLn h $ toolDocTxt tool
|
BC.hPutStrLn h $ manualTxt tool
|
||||||
hClose h
|
hClose h
|
||||||
envpager <- fromMaybe less <$> lookupEnv "PAGER"
|
envpager <- fromMaybe less <$> lookupEnv "PAGER"
|
||||||
let
|
let
|
||||||
@ -121,7 +129,7 @@ runManForTopic :: Tool -> Maybe Topic -> IO ()
|
|||||||
runManForTopic tool mtopic =
|
runManForTopic tool mtopic =
|
||||||
-- This temp file path should have a slash in it, man requires at least one.
|
-- This temp file path should have a slash in it, man requires at least one.
|
||||||
withSystemTempFile ("hledger-"++tool++".1") $ \f h -> do
|
withSystemTempFile ("hledger-"++tool++".1") $ \f h -> do
|
||||||
BC.hPutStrLn h $ toolDocMan tool
|
BC.hPutStrLn h $ manualMan tool
|
||||||
hClose h
|
hClose h
|
||||||
let
|
let
|
||||||
exactmatch = True
|
exactmatch = True
|
||||||
@ -130,3 +138,19 @@ runManForTopic tool mtopic =
|
|||||||
Nothing -> ""
|
Nothing -> ""
|
||||||
Just t -> "-P \"" ++ less ++ " -p'^( )?" ++ t ++ (if exactmatch then "\\\\$" else "") ++ "'\""
|
Just t -> "-P \"" ++ less ++ " -p'^( )?" ++ t ++ (if exactmatch then "\\\\$" else "") ++ "'\""
|
||||||
callCommand $ dbg1 "man command" $ unwords ["man", pagerarg, f]
|
callCommand $ dbg1 "man command" $ unwords ["man", pagerarg, f]
|
||||||
|
|
||||||
|
-- | Get the named tldr page's source, if we know it.
|
||||||
|
tldr :: TldrPage -> Maybe ByteString
|
||||||
|
tldr name = lookup name tldrs
|
||||||
|
|
||||||
|
-- | Display one of the hledger tldr pages, using "tldr".
|
||||||
|
runTldrForPage :: TldrPage -> IO ()
|
||||||
|
runTldrForPage name =
|
||||||
|
case tldr name of
|
||||||
|
Nothing -> error' $ "sorry, there's no " <> name <> " tldr page yet"
|
||||||
|
Just b -> do
|
||||||
|
withSystemTempFile (name++".md") $ \f h -> do
|
||||||
|
BC.hPutStrLn h b
|
||||||
|
hClose h
|
||||||
|
callCommand $ dbg1 "tldr command" $ unwords ["tldr", "-r", f]
|
||||||
|
|
||||||
|
|||||||
58
hledger/embeddedfiles/DEMOS.md
Normal file
58
hledger/embeddedfiles/DEMOS.md
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# Scripts and notes for demos
|
||||||
|
## install.cast
|
||||||
|
Installing hledger from source with hledger-install
|
||||||
|
https://asciinema.org/a/567934
|
||||||
|
|
||||||
|
``` 80x44
|
||||||
|
curl -O
|
||||||
|
https://raw.githubusercontent.com/simonmichael/hledger/master/hledger-install/hledger-install.sh
|
||||||
|
|
||||||
|
ls -l hledger-install.sh less hledger-install.sh
|
||||||
|
|
||||||
|
bash hledger-install.sh
|
||||||
|
```
|
||||||
|
Issues:
|
||||||
|
- with PATH not set up, hledger-install does not find the stack it installed
|
||||||
|
|
||||||
|
## ghcup.cast
|
||||||
|
Installing hledger from source with ghcup
|
||||||
|
```
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org
|
||||||
|
```
|
||||||
|
|
||||||
|
Issues:
|
||||||
|
- ghcup installs an older version of ghc 9.2
|
||||||
|
- with PATH not set up, ghcup does not find the cabal it installed
|
||||||
|
|
||||||
|
## help.cast
|
||||||
|
Getting help
|
||||||
|
### Things to cover
|
||||||
|
#### hledger
|
||||||
|
show this commands list
|
||||||
|
#### hledger -h
|
||||||
|
show hledger's command-line help
|
||||||
|
#### hledger CMD -h
|
||||||
|
show CMD's command-line help and manual
|
||||||
|
#### hledger help [-i|-m|-p] [TOPIC]
|
||||||
|
show hledger's manual with info, man, or pager
|
||||||
|
#### hledger demo [DEMO] -- [ASCOPTS]
|
||||||
|
show brief demos on various topics
|
||||||
|
#### https://hledger.org
|
||||||
|
html manuals, tutorials, support
|
||||||
|
|
||||||
|
## demo.cast
|
||||||
|
Watching the built-in demos
|
||||||
|
https://asciinema.org/a/567944
|
||||||
|
|
||||||
|
## add.cast
|
||||||
|
The simplest way to start a journal (add)
|
||||||
|
https://asciinema.org/a/567935
|
||||||
|
|
||||||
|
## print.cast
|
||||||
|
Show full transactions (print)
|
||||||
|
https://asciinema.org/a/567936
|
||||||
|
|
||||||
|
## balance.cast
|
||||||
|
Show account balances and changes (balance)
|
||||||
|
https://asciinema.org/a/567937
|
||||||
|
|
||||||
@ -2,6 +2,8 @@ These files are embedded into the hledger executable at compile time.
|
|||||||
They include:
|
They include:
|
||||||
|
|
||||||
- symbolic links to all the main hledger manuals in several formats, for embedding in Hledger/Cli/DocFiles.hs.
|
- symbolic links to all the main hledger manuals in several formats, for embedding in Hledger/Cli/DocFiles.hs.
|
||||||
(Having these symlinked here within the hledger package allows embedding them without using absolute paths.)
|
(Having the hledger-ui/hledger-web files also symlinked here within the hledger package allows embedding them without using absolute paths.)
|
||||||
|
|
||||||
|
- symbolic links to all the hledger tldr pages.
|
||||||
|
|
||||||
- asciinema screen casts, for embedding in Hledger/Cli/Commands/Demo.hs.
|
- asciinema screen casts, for embedding in Hledger/Cli/Commands/Demo.hs.
|
||||||
|
|||||||
1
hledger/embeddedfiles/README.md
Symbolic link
1
hledger/embeddedfiles/README.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/README.md
|
||||||
1
hledger/embeddedfiles/hledger-accounts.md
Symbolic link
1
hledger/embeddedfiles/hledger-accounts.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-accounts.md
|
||||||
1
hledger/embeddedfiles/hledger-add.md
Symbolic link
1
hledger/embeddedfiles/hledger-add.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-add.md
|
||||||
1
hledger/embeddedfiles/hledger-aregister.md
Symbolic link
1
hledger/embeddedfiles/hledger-aregister.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-aregister.md
|
||||||
1
hledger/embeddedfiles/hledger-balance.md
Symbolic link
1
hledger/embeddedfiles/hledger-balance.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-balance.md
|
||||||
1
hledger/embeddedfiles/hledger-balancesheet.md
Symbolic link
1
hledger/embeddedfiles/hledger-balancesheet.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-balancesheet.md
|
||||||
1
hledger/embeddedfiles/hledger-import.md
Symbolic link
1
hledger/embeddedfiles/hledger-import.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-import.md
|
||||||
1
hledger/embeddedfiles/hledger-incomestatement.md
Symbolic link
1
hledger/embeddedfiles/hledger-incomestatement.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-incomestatement.md
|
||||||
1
hledger/embeddedfiles/hledger-journal.md
Symbolic link
1
hledger/embeddedfiles/hledger-journal.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-journal.md
|
||||||
1
hledger/embeddedfiles/hledger-print.md
Symbolic link
1
hledger/embeddedfiles/hledger-print.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-print.md
|
||||||
1
hledger/embeddedfiles/hledger-ui.md
Symbolic link
1
hledger/embeddedfiles/hledger-ui.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-ui.md
|
||||||
1
hledger/embeddedfiles/hledger-web.md
Symbolic link
1
hledger/embeddedfiles/hledger-web.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger-web.md
|
||||||
1
hledger/embeddedfiles/hledger.md
Symbolic link
1
hledger/embeddedfiles/hledger.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../doc/tldr/hledger.md
|
||||||
@ -26,15 +26,28 @@ tested-with: GHC==8.10.7, GHC==9.0.2, GHC==9.2.8, GHC==9.4.5, GHC==9.6.2
|
|||||||
extra-source-files:
|
extra-source-files:
|
||||||
- CHANGES.md
|
- CHANGES.md
|
||||||
- README.md
|
- README.md
|
||||||
- test/unittest.hs
|
|
||||||
- bench/10000x1000x10.journal
|
- bench/10000x1000x10.journal
|
||||||
- hledger.1
|
- shell-completion/hledger-completion.bash
|
||||||
- hledger.txt
|
- test/unittest.hs
|
||||||
- hledger.info
|
|
||||||
- embeddedfiles/add.cast
|
- embeddedfiles/add.cast
|
||||||
- embeddedfiles/balance.cast
|
- embeddedfiles/balance.cast
|
||||||
- embeddedfiles/install.cast
|
- embeddedfiles/install.cast
|
||||||
- embeddedfiles/print.cast
|
- embeddedfiles/print.cast
|
||||||
|
|
||||||
|
- embeddedfiles/hledger-accounts.md
|
||||||
|
- embeddedfiles/hledger-add.md
|
||||||
|
- embeddedfiles/hledger-aregister.md
|
||||||
|
- embeddedfiles/hledger-balance.md
|
||||||
|
- embeddedfiles/hledger-balancesheet.md
|
||||||
|
- embeddedfiles/hledger-import.md
|
||||||
|
- embeddedfiles/hledger-incomestatement.md
|
||||||
|
- embeddedfiles/hledger-journal.md
|
||||||
|
- embeddedfiles/hledger-print.md
|
||||||
|
- embeddedfiles/hledger-ui.md
|
||||||
|
- embeddedfiles/hledger-web.md
|
||||||
|
- embeddedfiles/hledger.md
|
||||||
|
|
||||||
- embeddedfiles/hledger.1
|
- embeddedfiles/hledger.1
|
||||||
- embeddedfiles/hledger.txt
|
- embeddedfiles/hledger.txt
|
||||||
- embeddedfiles/hledger.info
|
- embeddedfiles/hledger.info
|
||||||
@ -44,7 +57,7 @@ extra-source-files:
|
|||||||
- embeddedfiles/hledger-web.1
|
- embeddedfiles/hledger-web.1
|
||||||
- embeddedfiles/hledger-web.txt
|
- embeddedfiles/hledger-web.txt
|
||||||
- embeddedfiles/hledger-web.info
|
- embeddedfiles/hledger-web.info
|
||||||
- shell-completion/hledger-completion.bash
|
|
||||||
- Hledger/Cli/Commands/Accounts.txt
|
- Hledger/Cli/Commands/Accounts.txt
|
||||||
- Hledger/Cli/Commands/Activity.txt
|
- Hledger/Cli/Commands/Activity.txt
|
||||||
- Hledger/Cli/Commands/Add.txt
|
- Hledger/Cli/Commands/Add.txt
|
||||||
|
|||||||
@ -82,9 +82,15 @@ $ hledger -f somefile
|
|||||||
> /^Commands/
|
> /^Commands/
|
||||||
|
|
||||||
# ** 6. with -h, and possibly other common flags present, show general usage
|
# ** 6. with -h, and possibly other common flags present, show general usage
|
||||||
$ hledger -h --version -f /dev/null
|
$ hledger -h --version -f/dev/null
|
||||||
> /^hledger \[COMMAND\]/
|
> /^hledger \[COMMAND\]/
|
||||||
|
|
||||||
|
# ** 6b. XXX our moveFlagsAfterCommand plus the way cmdargs' argument-requiring flags
|
||||||
|
# consume a following flag rather than failing, means things like this go wrong
|
||||||
|
# (args are rearranged to -f -h --version /dev/null, shows version when it should show help):
|
||||||
|
#$ hledger -h --version -f /dev/null
|
||||||
|
#> /^hledger \[COMMAND\]/
|
||||||
|
|
||||||
# ** 7. with -h before a COMMAND, show command usage
|
# ** 7. with -h before a COMMAND, show command usage
|
||||||
$ hledger -h balance --cost
|
$ hledger -h balance --cost
|
||||||
> /balance \[OPTIONS\]/
|
> /balance \[OPTIONS\]/
|
||||||
@ -104,7 +110,7 @@ $ hledger nosuchcommand
|
|||||||
$ hledger -f /dev/null --alias somealiases --rules-file --debug 1 --daily register
|
$ hledger -f /dev/null --alias somealiases --rules-file --debug 1 --daily register
|
||||||
|
|
||||||
# ** 11. or after it, and spaces in options are optional
|
# ** 11. or after it, and spaces in options are optional
|
||||||
$ hledger register -f/dev/null --alias=somealiases --rules-file -h --version --debug 1 --daily
|
$ hledger register -f/dev/null --alias=somealiases -h --version --debug 1 --daily
|
||||||
> /^register \[OPTIONS\]/
|
> /^register \[OPTIONS\]/
|
||||||
|
|
||||||
# ** 12. general flags before command should work
|
# ** 12. general flags before command should work
|
||||||
@ -117,4 +123,3 @@ $ hledger -f /dev/null register --daily
|
|||||||
$ hledger --related register
|
$ hledger --related register
|
||||||
>2 /Unknown flag: --related/
|
>2 /Unknown flag: --related/
|
||||||
>= 1
|
>= 1
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user