dev: Commands: cleanup, fix harmless bug in command finding

This commit is contained in:
Simon Michael 2023-01-12 23:58:17 -10:00
parent 7408bc02df
commit 173f61bee0

View File

@ -103,7 +103,7 @@ builtinCommands = [
,(closemode , close) ,(closemode , close)
,(codesmode , codes) ,(codesmode , codes)
,(commoditiesmode , commodities) ,(commoditiesmode , commodities)
,(descriptionsmode , descriptions) ,(descriptionsmode , descriptions)
,(diffmode , diff) ,(diffmode , diff)
,(filesmode , files) ,(filesmode , files)
,(helpmode , help') ,(helpmode , help')
@ -187,10 +187,14 @@ commandsList progversion othercmds highlight0 =
(if highlight then (map (\s -> if "+" `isPrefixOf` s then highlightAddon (' ' : drop 1 s) else s)) else id) $ (if highlight then (map (\s -> if "+" `isPrefixOf` s then highlightAddon (' ' : drop 1 s) else s)) else id) $
map (bold'.accent) _banner_smslant ++ map (bold'.accent) _banner_smslant ++
[ [
-- keep synced with hledger.m4.md > PART 4: COMMANDS, Hledger/Cli/Commands > commands.m4 --> -- Keep the following synced with:
-----------------------------------------80------------------------------------- -- commands.m4
"" -- hledger.m4.md -> Commands
,accent progversion -- commandsFromCommandsList. Only commands should begin with space or plus.
"-------------------------------------------------------------------------------"
,progversion
,"Usage: hledger COMMAND [OPTIONS] [-- ADDONCMDOPTIONS]"
,"Commands (+ addons found in $PATH):"
,"" ,""
,"Usage: " ++ bold' "hledger CMD [OPTS] [-- ADDONCMDOPTS]" ,"Usage: " ++ bold' "hledger CMD [OPTS] [-- ADDONCMDOPTS]"
,"" ,""
@ -296,11 +300,10 @@ findCommand cmdname = find (elem cmdname . modeNames . fst) builtinCommands
-- | Extract the command names from commandsList: the first word -- | Extract the command names from commandsList: the first word
-- of lines beginning with a space or + sign. -- of lines beginning with a space or + sign.
commandsFromCommandsList :: [String] -> [String] commandsFromCommandsList :: [String] -> [String]
commandsFromCommandsList s = 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 [] False -- progname will not be seen knownCommands = sort . commandsFromCommandsList $ 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