lib: Hledger.Cli.Commands: findCommand -> findBuiltinCommand
This commit is contained in:
parent
3961dbc044
commit
ae4f58beb7
@ -10,10 +10,10 @@ the export list, the import list, builtinCommands, commandsList.
|
|||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
|
||||||
module Hledger.Cli.Commands (
|
module Hledger.Cli.Commands (
|
||||||
findCommand
|
|
||||||
,testcmd
|
,testcmd
|
||||||
,builtinCommands
|
,builtinCommands
|
||||||
,builtinCommandNames
|
,builtinCommandNames
|
||||||
|
,findBuiltinCommand
|
||||||
,printCommandsList
|
,printCommandsList
|
||||||
,tests_Hledger_Cli
|
,tests_Hledger_Cli
|
||||||
,module Hledger.Cli.Commands.Accounts
|
,module Hledger.Cli.Commands.Accounts
|
||||||
@ -294,9 +294,6 @@ multicol width strs =
|
|||||||
builtinCommandNames :: [String]
|
builtinCommandNames :: [String]
|
||||||
builtinCommandNames = concatMap (modeNames . fst) builtinCommands
|
builtinCommandNames = concatMap (modeNames . fst) builtinCommands
|
||||||
|
|
||||||
-- | Look up a builtin command's mode and action by exact command name or alias.
|
|
||||||
findCommand :: String -> Maybe (Mode RawOpts, CliOpts -> Journal -> IO ())
|
|
||||||
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.
|
||||||
@ -309,6 +306,9 @@ knownCommands = sort . commandsFromCommandsList $ commandsList progname [] False
|
|||||||
-- | 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
|
||||||
-- extra addons will be added under Misc.
|
-- extra addons will be added under Misc.
|
||||||
|
-- | Look up a builtin command's mode and action by exact command name or alias.
|
||||||
|
findBuiltinCommand :: String -> Maybe (Mode RawOpts, CliOpts -> Journal -> IO ())
|
||||||
|
findBuiltinCommand cmdname = find (elem cmdname . modeNames . fst) builtinCommands
|
||||||
printCommandsList :: String -> [String] -> IO ()
|
printCommandsList :: String -> [String] -> IO ()
|
||||||
printCommandsList progversion addonsFound =
|
printCommandsList progversion addonsFound =
|
||||||
pager . unlines . concatMap adjustline $
|
pager . unlines . concatMap adjustline $
|
||||||
|
|||||||
@ -180,7 +180,7 @@ main = do
|
|||||||
| isBadCommand = badCommandError
|
| isBadCommand = badCommandError
|
||||||
|
|
||||||
-- builtin commands
|
-- builtin commands
|
||||||
| Just (cmdmode, cmdaction) <- findCommand 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` ["test","help"] -> cmdaction opts journallesserror
|
_ | cmd `elem` ["test","help"] -> cmdaction opts journallesserror
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user