cli: commands list: fix addons being shown twice
This commit is contained in:
parent
2442b4f46f
commit
8d6b5cc4f3
@ -44,7 +44,6 @@ where
|
|||||||
import Data.Char (isSpace)
|
import Data.Char (isSpace)
|
||||||
import Data.Default
|
import Data.Default
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.List.Split (splitOn)
|
|
||||||
#if !(MIN_VERSION_base(4,11,0))
|
#if !(MIN_VERSION_base(4,11,0))
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
#endif
|
#endif
|
||||||
@ -210,7 +209,7 @@ printCommandsList :: [String] -> IO ()
|
|||||||
printCommandsList addonsFound =
|
printCommandsList addonsFound =
|
||||||
putStr $
|
putStr $
|
||||||
regexReplace "PROGVERSION" (prognameandversion) $
|
regexReplace "PROGVERSION" (prognameandversion) $
|
||||||
regexReplace "OTHER" (unlines unknownCommandsFound) $
|
regexReplace "OTHER" (unlines $ (map ('+':) unknownCommandsFound)) $
|
||||||
-- regexReplace "COUNT" (show cmdcount) $
|
-- regexReplace "COUNT" (show cmdcount) $
|
||||||
unlines $ concatMap adjustline $ lines $
|
unlines $ concatMap adjustline $ lines $
|
||||||
cmdlist
|
cmdlist
|
||||||
@ -218,7 +217,7 @@ printCommandsList addonsFound =
|
|||||||
cmdlist = commandsList
|
cmdlist = commandsList
|
||||||
-- cmdcount = length $ commandsFromCommandsList cmdlist
|
-- cmdcount = length $ commandsFromCommandsList cmdlist
|
||||||
commandsFound = map (' ':) builtinCommandNames ++ map ('+':) addonsFound
|
commandsFound = map (' ':) builtinCommandNames ++ map ('+':) addonsFound
|
||||||
unknownCommandsFound = map ('+':) $ addonsFound \\ knownCommands
|
unknownCommandsFound = addonsFound \\ knownCommands
|
||||||
|
|
||||||
adjustline l | " hledger " `isPrefixOf` l = [l]
|
adjustline l | " hledger " `isPrefixOf` l = [l]
|
||||||
adjustline l@('+':_) | not $ cmd `elem` commandsFound = []
|
adjustline l@('+':_) | not $ cmd `elem` commandsFound = []
|
||||||
@ -229,11 +228,11 @@ printCommandsList addonsFound =
|
|||||||
knownCommands :: [String]
|
knownCommands :: [String]
|
||||||
knownCommands = sort $ commandsFromCommandsList commandsList
|
knownCommands = sort $ commandsFromCommandsList commandsList
|
||||||
|
|
||||||
-- | Extract the command names from a commands list like the above:
|
-- | Extract the command names from commandsList: the first word
|
||||||
-- the first word (or words separated by |) of lines beginning with a space.
|
-- of lines beginning with a space or + sign.
|
||||||
commandsFromCommandsList :: String -> [String]
|
commandsFromCommandsList :: String -> [String]
|
||||||
commandsFromCommandsList s =
|
commandsFromCommandsList s =
|
||||||
concatMap (splitOn "|") [w | ' ':l <- lines s, let w:_ = words l]
|
[w | c:l <- lines s, c `elem` [' ','+'], let w:_ = words l]
|
||||||
|
|
||||||
|
|
||||||
-- The test command is defined here for easy access to other modules' tests.
|
-- The test command is defined here for easy access to other modules' tests.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user