help: show only the hledger manual, for now

This commit is contained in:
Simon Michael 2020-12-25 16:31:30 -08:00
parent 7d3f05b16a
commit f20cd2b112
2 changed files with 25 additions and 51 deletions

View File

@ -19,10 +19,7 @@ module Hledger.Cli.Commands.Help (
import Prelude ()
import "base-compat-batteries" Prelude.Compat
import Data.Char
import Data.List
import Data.Maybe
import Safe
import System.Console.CmdArgs.Explicit
import System.Environment
import System.IO
@ -43,9 +40,9 @@ helpmode = hledgerCommandMode
]
[]
[]
([], Just $ argsFlag "[MANUAL]")
([], Nothing) -- Just $ argsFlag "[TOPIC]"
-- | List or display one of the hledger manuals in various formats.
-- | Display the hledger manual in various formats.
-- You can select a docs viewer with one of the `--info`, `--man`, `--pager` flags.
-- Otherwise it will use the first available of: info, man, $PAGER, less, stdout
-- (and always stdout if output is non-interactive).
@ -55,10 +52,10 @@ help' opts _ = do
pagerprog <- fromMaybe "less" <$> lookupEnv "PAGER"
interactive <- hIsTerminalDevice stdout
let
args = take 1 $ listofstringopt "args" $ rawopts_ opts
topic = case args of
[pat] -> headMay [t | t <- docTopics, map toLower pat `isInfixOf` t]
_ -> Nothing
-- args = take 1 $ listofstringopt "args" $ rawopts_ opts
-- topic = case args of
-- [pat] -> headMay [t | t <- docTopics, map toLower pat `isInfixOf` t]
-- _ -> Nothing
[info, man, pager, cat] =
[runInfoForTopic, runManForTopic, runPagerForTopic pagerprog, printHelpForTopic]
viewer
@ -70,11 +67,12 @@ help' opts _ = do
| "man" `elem` exes = man
| pagerprog `elem` exes = pager
| otherwise = cat
case topic of
Nothing -> putStrLn $ unlines [
"Please choose a manual by typing \"hledger help MANUAL\" (any substring is ok)."
,"A viewer (info, man, $PAGER, or stdout) will be auto-selected,"
,"or type \"hledger help -h\" to see options. Manuals available:"
]
++ "\n " ++ unwords docTopics
Just t -> viewer t
viewer "hledger"
-- case topic of
-- Nothing -> putStrLn $ unlines [
-- "Please choose a manual by typing \"hledger help MANUAL\" (any substring is ok)."
-- ,"A viewer (info, man, $PAGER, or stdout) will be auto-selected,"
-- ,"or type \"hledger help -h\" to see options. Manuals available:"
-- ]
-- ++ "\n " ++ unwords docTopics
-- Just t -> viewer t

View File

@ -1,40 +1,16 @@
help\
Show any of the hledger manuals.
Show the hledger user manual in one of several formats.
_FLAGS
The `help` command displays any of the main [hledger user manuals](https://hledger.org/index.html),
in one of several ways.
Run it with no argument to list the manuals, or provide a full or partial manual name to select one.
This command shows the user manual built in to this hledger version,
using the best viewer it can find.
It can be useful if the correct version of the hledger manual,
or the usual viewing tools, are not installed on your system.
hledger manuals are available in several formats.
hledger help will use the first of these display methods that it finds:
info, man, $PAGER, less, stdout (or when non-interactive, just stdout).
You can force a particular viewer with the `--info/-i`, `--man/-m`,
`--pager/-p` flags.
It will use the first of these viewers that it finds in $PATH:
`info`, `man`, $PAGER, `less`, or stdout.
When run non-interactively, it always uses stdout.
Or you can force a particular viewer with the
`--info/-i`, `--man/-m`, or `--pager/-p` flags.
Examples:
```shell
$ hledger help
Please choose a manual by typing "hledger help MANUAL" (a substring is ok).
Manuals: hledger hledger-ui hledger-web
```
```shell
$ hledger help h --man
hledger(1) hledger User Manuals hledger(1)
NAME
hledger - a command-line accounting tool
SYNOPSIS
hledger [-f FILE] COMMAND [OPTIONS] [ARGS]
hledger [-f FILE] ADDONCMD -- [OPTIONS] [ARGS]
hledger
DESCRIPTION
hledger is a cross-platform program for tracking money, time, or any
...
```