cli: new, comprehensive commands list

This commit is contained in:
Simon Michael 2017-09-14 05:55:44 -07:00
parent bc66c75bd2
commit 6e7a14b656

View File

@ -48,6 +48,7 @@ import Test.HUnit
import Hledger import Hledger
import Hledger.Cli.CliOptions import Hledger.Cli.CliOptions
import Hledger.Cli.Version
import Hledger.Cli.Commands.Accounts import Hledger.Cli.Commands.Accounts
import Hledger.Cli.Commands.Activity import Hledger.Cli.Commands.Activity
import Hledger.Cli.Commands.Add import Hledger.Cli.Commands.Add
@ -74,20 +75,27 @@ import Hledger.Cli.Commands.Tags
-- Command actions take parsed CLI options and a (lazy) finalised journal. -- Command actions take parsed CLI options and a (lazy) finalised journal.
builtinCommands :: [(Mode RawOpts, CliOpts -> Journal -> IO ())] builtinCommands :: [(Mode RawOpts, CliOpts -> Journal -> IO ())]
builtinCommands = [ builtinCommands = [
(accountsmode , accounts) (accountsmode , accounts)
,(activitymode , activity) ,(activitymode , activity)
,(addmode , add) ,(addmode , add)
,(balancemode , balance) ,(balancemode , balance)
,(balancesheetmode , balancesheet) ,(balancesheetmode , balancesheet)
,(balancesheetequitymode , balancesheetequity) ,(balancesheetequitymode , balancesheetequity)
,(cashflowmode , cashflow) ,(cashflowmode , cashflow)
,(checkdatesmode , checkdates) ,(checkdatesmode , checkdates)
,(helpmode , help') ,(checkdupesmode , checkdupes)
,(incomestatementmode , incomestatement) ,(equitymode , equity)
,(printmode , print') ,(helpmode , help')
,(registermode , register) ,(incomestatementmode , incomestatement)
,(statsmode , stats) ,(pricesmode , prices)
,(testmode , testcmd) ,(printmode , print')
,(printuniquemode , printunique)
,(registermode , register)
,(registermatchmode , registermatch)
,(rewritemode , rewrite)
,(statsmode , stats)
,(tagsmode , tags)
,(testmode , testcmd)
] ]
-- | All names and aliases of builtin commands. -- | All names and aliases of builtin commands.
@ -99,68 +107,85 @@ findCommand :: String -> Maybe (Mode RawOpts, CliOpts -> Journal -> IO ())
findCommand cmdname = find (elem cmdname . modeNames . fst) builtinCommands findCommand cmdname = find (elem cmdname . modeNames . fst) builtinCommands
-- | A template for the commands list, containing entries (indented lines) -- | A template for the commands list, containing entries (indented lines)
-- for all currently known builtin and addon commands. -- for all known and some hypothetical builtin and addon commands.
-- These will be filtered based on the commands found at runtime, -- These will be filtered based on the commands found at runtime,
-- except those beginning with "hledger", which are not filtered. -- except those beginning with "hledger", which are not filtered.
-- OTHERCMDS is replaced with an entry for each unknown addon command found. -- PROGVERSION is replaced with the program name and version.
-- COUNT is replaced with the number of commands found. -- OTHER is replaced with an entry for each unknown addon command found.
-- --
-- The command descriptions here should be kept synced with -- The command descriptions here should be kept synced with
-- each command's builtin help and with hledger manual's command list. -- each command's builtin help and with hledger manual's command list.
-- --
commandsListTemplate :: String commandsList :: String
commandsListTemplate = [here|Commands available (COUNT): commandsList = [here|
-------------------------------------------------------------------------------
PROGVERSION, commands available:
Standard reports: Statements:
accounts show chart of accounts balancesheet (bs) show a simple balance sheet with net worth
balancesheet (bs) show a balance sheet balancesheetequity (bse) show a detailed balance sheet with equity
balancesheetequity (bse) show a balance sheet with equity cashflow (cf) show a cashflow statement
cashflow (cf) show a cashflow statement incomestatement (is) show an income statement
incomestatement (is) show an income statement
transactions (txns) show transactions in some account
General reporting: Basic reports:
activity show a bar chart of posting counts per interval accounts (a) show account names
balance (bal) show accounts and balances activity show a chart of posting counts per interval
budget add automated postings/txns/bucket accts (experimental) aregister (ar, areg) show transactions in a single account
chart generate simple balance pie charts (experimental) balance (b, bal) show account balance changes or ending balances
check check more powerful balance assertions prices show market price records
check-dates check transactions are ordered by date print (p, txns) show transactions/journal entries
check-dupes check for accounts with the same leaf name register (r, reg) show postings to one or more accounts
irr calculate internal rate of return of an investment stats show journal statistics
prices show market price records tags show tag names
print show transaction journal entries
print-unique show only transactions with unique descriptions
register (reg) show postings and running total
register-match show best matching transaction for a description
stats show some journal statistics
Interfaces: Modifying data:
add console ui for adding transactions add add transactions using console ui
api web api server iadd add transactions using curses ui
iadd curses ui for adding transactions import add new transactions from one or more import files
ui curses ui edit open a text editor on some part of the journal
web web ui equity generate balance-resetting transactions
interest generate interest transactions
rewrite generate automated postings on matched transactions
Misc: UIs:
autosync download/deduplicate/convert OFX data api start web api server
equity generate transactions to zero & restore account balances ui start curses ui
interest generate interest transactions web start web ui
rewrite add automated postings to certain transactions
test run some self tests Other/experimental:
OTHERCMDS autosync download/deduplicate/convert OFX data
budget add automated postings/txns/bucket accts
chart generate simple balance pie charts
check check more powerful balance assertions
check-dates check transactions are ordered by date
check-dupes check for accounts with the same leaf name
diff compare account transactions in two journal files
irr calculate internal rate of return of an investment
print-unique show only transactions with unique descriptions
register-match show best matching transaction for a description
test run self tests
OTHER
Help: Help:
help show any of the hledger manuals in various formats help show any of the hledger manuals in various formats
hledger CMD -h show command usage hledger CMD -h show command usage
hledger -h show general usage hledger -h show general usage
-------------------------------------------------------------------------------
|] |]
-- | 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.
printCommandsList :: [String] -> IO () printCommandsList :: [String] -> IO ()
printCommandsList addonsFound = putStr commandsList printCommandsList addonsFound =
putStr $
regexReplace "PROGVERSION" (prognameandversion) $
regexReplace "OTHER" (unlines $ map (' ':) unknownCommandsFound) $
-- regexReplace "COUNT" (show cmdcount) $
unlines $ concatMap adjustline $ lines $
cmdlist
where where
cmdlist = commandsList
-- cmdcount = length $ commandsFromCommandsList cmdlist
commandsFound = builtinCommandNames ++ addonsFound commandsFound = builtinCommandNames ++ addonsFound
unknownCommandsFound = addonsFound \\ knownCommands unknownCommandsFound = addonsFound \\ knownCommands
@ -169,21 +194,14 @@ printCommandsList addonsFound = putStr commandsList
where w = takeWhile (not . (`elem` ['|',' '])) l where w = takeWhile (not . (`elem` ['|',' '])) l
adjustline l = [l] adjustline l = [l]
commandsList1 =
regexReplace "OTHERCMDS" (unlines [' ':w | w <- unknownCommandsFound]) $
unlines $ concatMap adjustline $ lines commandsListTemplate
commandsList =
regexReplace "COUNT" (show $ length $ commandsFromCommandsList commandsList1)
commandsList1
knownCommands :: [String] knownCommands :: [String]
knownCommands = sort $ commandsFromCommandsList commandsListTemplate knownCommands = sort $ commandsFromCommandsList commandsList
-- | Extract the command names from a commands list like the above: -- | Extract the command names from a commands list like the above:
-- the first word (or words separated by |) of lines beginning with a space. -- the first word (or words separated by |) of lines beginning with a space.
commandsFromCommandsList :: String -> [String] commandsFromCommandsList :: String -> [String]
commandsFromCommandsList s = concatMap (splitOn "|") [w | ' ':l <- lines s, let w:_ = words l] commandsFromCommandsList s =
concatMap (splitOn "|") [w | ' ':l <- lines s, let w:_ = words l]