mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-19 10:17:35 +03:00
refactor: Commands
This commit is contained in:
parent
8d6b5cc4f3
commit
88ef2abfff
@ -5,9 +5,9 @@ New built-in commands should be added in four places below:
|
|||||||
the export list, the import list, builtinCommands, commandsList.
|
the export list, the import list, builtinCommands, commandsList.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
{-# LANGUAGE CPP #-}
|
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
|
||||||
module Hledger.Cli.Commands (
|
module Hledger.Cli.Commands (
|
||||||
@ -189,9 +189,8 @@ Help:
|
|||||||
(no arguments) show this commands list
|
(no arguments) show this commands list
|
||||||
|
|
||||||
|]
|
|]
|
||||||
-- -------------------------------------------------------------------------------
|
|
||||||
-- aregister (ar, areg) show transactions in a single account
|
|
||||||
-- edit open a text editor on some part of the journal
|
-- edit open a text editor on some part of the journal
|
||||||
|
-- aregister (ar, areg) show transactions in a single account
|
||||||
|
|
||||||
|
|
||||||
-- | All names and aliases of builtin commands.
|
-- | All names and aliases of builtin commands.
|
||||||
@ -202,6 +201,15 @@ builtinCommandNames = concatMap (modeNames . fst) builtinCommands
|
|||||||
findCommand :: String -> Maybe (Mode RawOpts, CliOpts -> Journal -> IO ())
|
findCommand :: String -> Maybe (Mode RawOpts, CliOpts -> Journal -> IO ())
|
||||||
findCommand cmdname = find (elem cmdname . modeNames . fst) builtinCommands
|
findCommand cmdname = find (elem cmdname . modeNames . fst) builtinCommands
|
||||||
|
|
||||||
|
-- | Extract the command names from commandsList: the first word
|
||||||
|
-- of lines beginning with a space or + sign.
|
||||||
|
commandsFromCommandsList :: String -> [String]
|
||||||
|
commandsFromCommandsList s =
|
||||||
|
[w | c:l <- lines s, c `elem` [' ','+'], let w:_ = words l]
|
||||||
|
|
||||||
|
knownCommands :: [String]
|
||||||
|
knownCommands = sort $ commandsFromCommandsList commandsList
|
||||||
|
|
||||||
-- | 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.
|
||||||
@ -210,12 +218,10 @@ printCommandsList addonsFound =
|
|||||||
putStr $
|
putStr $
|
||||||
regexReplace "PROGVERSION" (prognameandversion) $
|
regexReplace "PROGVERSION" (prognameandversion) $
|
||||||
regexReplace "OTHER" (unlines $ (map ('+':) unknownCommandsFound)) $
|
regexReplace "OTHER" (unlines $ (map ('+':) unknownCommandsFound)) $
|
||||||
-- regexReplace "COUNT" (show cmdcount) $
|
|
||||||
unlines $ concatMap adjustline $ lines $
|
unlines $ concatMap adjustline $ lines $
|
||||||
cmdlist
|
cmdlist
|
||||||
where
|
where
|
||||||
cmdlist = commandsList
|
cmdlist = commandsList
|
||||||
-- cmdcount = length $ commandsFromCommandsList cmdlist
|
|
||||||
commandsFound = map (' ':) builtinCommandNames ++ map ('+':) addonsFound
|
commandsFound = map (' ':) builtinCommandNames ++ map ('+':) addonsFound
|
||||||
unknownCommandsFound = addonsFound \\ knownCommands
|
unknownCommandsFound = addonsFound \\ knownCommands
|
||||||
|
|
||||||
@ -225,15 +231,6 @@ printCommandsList addonsFound =
|
|||||||
cmd = takeWhile (not . isSpace) l
|
cmd = takeWhile (not . isSpace) l
|
||||||
adjustline l = [l]
|
adjustline l = [l]
|
||||||
|
|
||||||
knownCommands :: [String]
|
|
||||||
knownCommands = sort $ commandsFromCommandsList commandsList
|
|
||||||
|
|
||||||
-- | Extract the command names from commandsList: the first word
|
|
||||||
-- of lines beginning with a space or + sign.
|
|
||||||
commandsFromCommandsList :: String -> [String]
|
|
||||||
commandsFromCommandsList s =
|
|
||||||
[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