imp: cli: add a little highlighting to help output
This commit is contained in:
parent
0de3acabcb
commit
72cd441a9f
@ -87,6 +87,7 @@ import Data.Maybe
|
|||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Void (Void)
|
import Data.Void (Void)
|
||||||
import Safe
|
import Safe
|
||||||
|
import String.ANSI
|
||||||
import System.Console.CmdArgs hiding (Default,def)
|
import System.Console.CmdArgs hiding (Default,def)
|
||||||
import System.Console.CmdArgs.Explicit
|
import System.Console.CmdArgs.Explicit
|
||||||
import System.Console.CmdArgs.Text
|
import System.Console.CmdArgs.Text
|
||||||
@ -396,8 +397,25 @@ parseCommandDoc t =
|
|||||||
|
|
||||||
-- | Get a mode's usage message as a nicely wrapped string.
|
-- | Get a mode's usage message as a nicely wrapped string.
|
||||||
showModeUsage :: Mode a -> String
|
showModeUsage :: Mode a -> String
|
||||||
showModeUsage = (showText defaultWrap :: [Text] -> String) .
|
showModeUsage =
|
||||||
(helpText [] HelpFormatDefault :: Mode a -> [Text])
|
highlightHelp .
|
||||||
|
(showText defaultWrap :: [Text] -> String) .
|
||||||
|
(helpText [] HelpFormatDefault :: Mode a -> [Text])
|
||||||
|
|
||||||
|
-- | Add some ANSI decoration to cmdargs' help output.
|
||||||
|
highlightHelp = unlines . zipWith (curry f) [1..] . lines
|
||||||
|
where
|
||||||
|
f (n,s)
|
||||||
|
| n==1 = bold s
|
||||||
|
| s `elem` [
|
||||||
|
"General input flags:"
|
||||||
|
,"General reporting flags:"
|
||||||
|
,"General help flags:"
|
||||||
|
,"Flags:"
|
||||||
|
,"General flags:"
|
||||||
|
,"Examples:"
|
||||||
|
] = bold s
|
||||||
|
| otherwise = s
|
||||||
|
|
||||||
-- | Get the most appropriate documentation topic for a mode.
|
-- | Get the most appropriate documentation topic for a mode.
|
||||||
-- Currently, that is either the hledger, hledger-ui or hledger-web
|
-- Currently, that is either the hledger, hledger-ui or hledger-web
|
||||||
|
|||||||
@ -48,6 +48,7 @@ import Data.List
|
|||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
|
import String.ANSI
|
||||||
import System.Environment (withArgs)
|
import System.Environment (withArgs)
|
||||||
import System.Console.CmdArgs.Explicit as C
|
import System.Console.CmdArgs.Explicit as C
|
||||||
import Test.Tasty (defaultMain)
|
import Test.Tasty (defaultMain)
|
||||||
@ -120,6 +121,8 @@ builtinCommands = [
|
|||||||
,(testmode , testcmd)
|
,(testmode , testcmd)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
accent = blue
|
||||||
|
|
||||||
-- figlet -f FONTNAME hledger, then escape backslashes
|
-- figlet -f FONTNAME hledger, then escape backslashes
|
||||||
_banner_slant = drop 1 [""
|
_banner_slant = drop 1 [""
|
||||||
-----------------------------------------80-------------------------------------
|
-----------------------------------------80-------------------------------------
|
||||||
@ -131,7 +134,7 @@ _banner_slant = drop 1 [""
|
|||||||
," /____/ "
|
," /____/ "
|
||||||
]
|
]
|
||||||
|
|
||||||
_banner_smslant = drop 1 [""
|
_banner_smslant = map accent $ drop 1 [""
|
||||||
," __ __ __ "
|
," __ __ __ "
|
||||||
," / / / /__ ___/ /__ ____ ____"
|
," / / / /__ ___/ /__ ____ ____"
|
||||||
," / _ \\/ / -_) _ / _ `/ -_) __/"
|
," / _ \\/ / -_) _ / _ `/ -_) __/"
|
||||||
@ -148,6 +151,8 @@ _banner_speed = drop 1 [""
|
|||||||
," /____/ "
|
," /____/ "
|
||||||
]
|
]
|
||||||
|
|
||||||
|
highlightAddon = id
|
||||||
|
|
||||||
-- | The commands list, showing command names, standard aliases,
|
-- | The commands list, showing command names, standard aliases,
|
||||||
-- and short descriptions. This is modified at runtime, as follows:
|
-- and short descriptions. This is modified at runtime, as follows:
|
||||||
--
|
--
|
||||||
@ -166,25 +171,26 @@ _banner_speed = drop 1 [""
|
|||||||
--
|
--
|
||||||
-- TODO: generate more of this automatically.
|
-- TODO: generate more of this automatically.
|
||||||
--
|
--
|
||||||
commandsList :: String -> [String] -> [String]
|
commandsList :: String -> [String] -> Bool -> [String]
|
||||||
commandsList progversion othercmds =
|
commandsList progversion othercmds highlight =
|
||||||
|
(if highlight then (map (\s -> if "+" `isPrefixOf` s then highlightAddon (' ' : drop 1 s) else s)) else id) $
|
||||||
_banner_smslant ++ [
|
_banner_smslant ++ [
|
||||||
-- keep synced with hledger.m4.md > PART 4: COMMANDS, Hledger/Cli/Commands > commands.m4 -->
|
-- keep synced with hledger.m4.md > PART 4: COMMANDS, Hledger/Cli/Commands > commands.m4 -->
|
||||||
-----------------------------------------80-------------------------------------
|
-----------------------------------------80-------------------------------------
|
||||||
""
|
""
|
||||||
,progversion
|
,accent progversion
|
||||||
|
,""
|
||||||
|
,"Usage: " ++ bold "hledger CMD [OPTS] [-- ADDONCMDOPTS]"
|
||||||
,""
|
,""
|
||||||
,"Usage: hledger COMMAND [OPTIONS] [-- ADDONCMDOPTIONS]"
|
|
||||||
,"Commands:"
|
,"Commands:"
|
||||||
,""
|
,bold "DATA ENTRY: add or edit entries in the journal file"
|
||||||
,"DATA ENTRY: add or edit entries in the journal file"
|
|
||||||
," add add transactions using terminal prompts"
|
," add add transactions using terminal prompts"
|
||||||
,"+edit edit a subset of transactions"
|
,"+edit edit a subset of transactions"
|
||||||
,"+iadd add transactions using a TUI"
|
,"+iadd add transactions using a TUI"
|
||||||
," import add new transactions from from other files, eg csv"
|
," import add new transactions from from other files, eg csv"
|
||||||
,""
|
,""
|
||||||
-----------------------------------------80-------------------------------------
|
-----------------------------------------80-------------------------------------
|
||||||
,"DATA CREATION: create or convert entries to be added to the journal file"
|
,bold "DATA CREATION: create or convert entries to be added to the journal file"
|
||||||
,"+autosync download/deduplicate/convert OFX data"
|
,"+autosync download/deduplicate/convert OFX data"
|
||||||
," close generate balance-zeroing/restoring transactions"
|
," close generate balance-zeroing/restoring transactions"
|
||||||
,"+interest generate interest transactions"
|
,"+interest generate interest transactions"
|
||||||
@ -192,7 +198,7 @@ commandsList progversion othercmds =
|
|||||||
,"+stockquotes download market prices from AlphaVantage"
|
,"+stockquotes download market prices from AlphaVantage"
|
||||||
,""
|
,""
|
||||||
-----------------------------------------80-------------------------------------
|
-----------------------------------------80-------------------------------------
|
||||||
,"DATA MANAGEMENT: help validate or manage journal files"
|
,bold "DATA MANAGEMENT: help validate or manage journal files"
|
||||||
," check check for various kinds of issue in the data"
|
," check check for various kinds of issue in the data"
|
||||||
,"+check-fancyassertions check more powerful balance assertions"
|
,"+check-fancyassertions check more powerful balance assertions"
|
||||||
,"+check-tagfiles check file paths in tag values exist"
|
,"+check-tagfiles check file paths in tag values exist"
|
||||||
@ -201,7 +207,7 @@ commandsList progversion othercmds =
|
|||||||
,"+pijul record/status/log journal changes easily with pijul"
|
,"+pijul record/status/log journal changes easily with pijul"
|
||||||
,""
|
,""
|
||||||
-----------------------------------------80-------------------------------------
|
-----------------------------------------80-------------------------------------
|
||||||
,"REPORTS, FINANCIAL: standard financial reports"
|
,bold "REPORTS, FINANCIAL: standard financial reports"
|
||||||
," aregister (areg) show transactions in a particular account"
|
," aregister (areg) show transactions in a particular account"
|
||||||
," balancesheet (bs) show assets, liabilities and net worth"
|
," balancesheet (bs) show assets, liabilities and net worth"
|
||||||
," balancesheetequity (bse) show assets, liabilities and equity"
|
," balancesheetequity (bse) show assets, liabilities and equity"
|
||||||
@ -209,7 +215,7 @@ commandsList progversion othercmds =
|
|||||||
," incomestatement (is) show revenues and expenses"
|
," incomestatement (is) show revenues and expenses"
|
||||||
,""
|
,""
|
||||||
-----------------------------------------80-------------------------------------
|
-----------------------------------------80-------------------------------------
|
||||||
,"REPORTS, VERSATILE: more complex/versatile reporting commands"
|
,bold "REPORTS, VERSATILE: more complex/versatile reporting commands"
|
||||||
," balance (bal) show balance changes, end balances, budgets, gains.."
|
," balance (bal) show balance changes, end balances, budgets, gains.."
|
||||||
,"+plot create charts from balance reports, in terminal or GUI"
|
,"+plot create charts from balance reports, in terminal or GUI"
|
||||||
," print show transactions or export journal data"
|
," print show transactions or export journal data"
|
||||||
@ -217,7 +223,7 @@ commandsList progversion othercmds =
|
|||||||
," roi show return on investments"
|
," roi show return on investments"
|
||||||
,""
|
,""
|
||||||
-----------------------------------------80-------------------------------------
|
-----------------------------------------80-------------------------------------
|
||||||
,"REPORTS, BASIC: simple reports"
|
,bold "REPORTS, BASIC: simple reports"
|
||||||
," accounts show account names"
|
," accounts show account names"
|
||||||
," activity show bar charts of posting counts per period"
|
," activity show bar charts of posting counts per period"
|
||||||
," codes show transaction codes"
|
," codes show transaction codes"
|
||||||
@ -232,17 +238,17 @@ commandsList progversion othercmds =
|
|||||||
," test run self tests"
|
," test run self tests"
|
||||||
,""
|
,""
|
||||||
-----------------------------------------80-------------------------------------
|
-----------------------------------------80-------------------------------------
|
||||||
,"UIS: other user interfaces"
|
,bold "UIS: other user interfaces"
|
||||||
,"+ui run terminal UI"
|
,"+ui run terminal UI"
|
||||||
,"+web run web UI"
|
,"+web run web UI"
|
||||||
,""
|
,""
|
||||||
,"OTHER: other hledger-* addon commands found in PATH"
|
,bold "OTHER: other hledger-* addon commands found in PATH"
|
||||||
] ++
|
] ++
|
||||||
multicol 80 (map ((' ':) . drop 1) othercmds)
|
multicol 80 (map (highlightAddon . (' ':) . drop 1) othercmds)
|
||||||
++
|
++
|
||||||
[""
|
[""
|
||||||
-----------------------------------------80-------------------------------------
|
-----------------------------------------80-------------------------------------
|
||||||
,"HELP: command-line help and more docs"
|
,bold "HELP: command-line help and more docs"
|
||||||
," hledger show this commands list"
|
," hledger show this commands list"
|
||||||
," hledger -h show hledger's general help"
|
," hledger -h show hledger's general help"
|
||||||
," hledger COMMAND -h show COMMAND's help"
|
," hledger COMMAND -h show COMMAND's help"
|
||||||
@ -282,7 +288,7 @@ commandsFromCommandsList s =
|
|||||||
[w | c:l <- s, c `elem` [' ','+'], let w:_ = words l]
|
[w | c:l <- s, c `elem` [' ','+'], let w:_ = words l]
|
||||||
|
|
||||||
knownCommands :: [String]
|
knownCommands :: [String]
|
||||||
knownCommands = sort . commandsFromCommandsList . drop 1 $ commandsList progname [] -- progname will not be seen
|
knownCommands = sort . commandsFromCommandsList . drop 1 $ commandsList progname [] False -- progname will not be seen
|
||||||
|
|
||||||
-- | Print the commands list, modifying the template above based on
|
-- | Print the commands list, modifying the template above based on
|
||||||
-- the currently available addons. Missing addons will be removed, and
|
-- the currently available addons. Missing addons will be removed, and
|
||||||
@ -290,7 +296,7 @@ knownCommands = sort . commandsFromCommandsList . drop 1 $ commandsList progname
|
|||||||
printCommandsList :: String -> [String] -> IO ()
|
printCommandsList :: String -> [String] -> IO ()
|
||||||
printCommandsList progversion addonsFound =
|
printCommandsList progversion addonsFound =
|
||||||
pager . unlines . concatMap adjustline $
|
pager . unlines . concatMap adjustline $
|
||||||
commandsList progversion (map ('+':) unknownCommandsFound)
|
commandsList progversion (map ('+':) unknownCommandsFound) True
|
||||||
where
|
where
|
||||||
commandsFound = map (' ':) builtinCommandNames ++ map ('+':) addonsFound
|
commandsFound = map (' ':) builtinCommandNames ++ map ('+':) addonsFound
|
||||||
unknownCommandsFound = addonsFound \\ knownCommands
|
unknownCommandsFound = addonsFound \\ knownCommands
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user