check: drop old checkdates/checkdupes commands, consolidate

This commit is contained in:
Simon Michael 2020-12-31 10:47:15 -08:00
parent a6ec7bcc11
commit 1d4c4c5b8b
11 changed files with 26 additions and 82 deletions

View File

@ -25,8 +25,6 @@ module Hledger.Cli.Commands (
,module Hledger.Cli.Commands.Balancesheet ,module Hledger.Cli.Commands.Balancesheet
,module Hledger.Cli.Commands.Balancesheetequity ,module Hledger.Cli.Commands.Balancesheetequity
,module Hledger.Cli.Commands.Cashflow ,module Hledger.Cli.Commands.Cashflow
,module Hledger.Cli.Commands.Checkdates
,module Hledger.Cli.Commands.Checkdupes
,module Hledger.Cli.Commands.Close ,module Hledger.Cli.Commands.Close
,module Hledger.Cli.Commands.Codes ,module Hledger.Cli.Commands.Codes
,module Hledger.Cli.Commands.Commodities ,module Hledger.Cli.Commands.Commodities
@ -73,8 +71,6 @@ import Hledger.Cli.Commands.Balancesheet
import Hledger.Cli.Commands.Balancesheetequity import Hledger.Cli.Commands.Balancesheetequity
import Hledger.Cli.Commands.Cashflow import Hledger.Cli.Commands.Cashflow
import Hledger.Cli.Commands.Check import Hledger.Cli.Commands.Check
import Hledger.Cli.Commands.Checkdates
import Hledger.Cli.Commands.Checkdupes
import Hledger.Cli.Commands.Close import Hledger.Cli.Commands.Close
import Hledger.Cli.Commands.Codes import Hledger.Cli.Commands.Codes
import Hledger.Cli.Commands.Commodities import Hledger.Cli.Commands.Commodities
@ -111,8 +107,6 @@ builtinCommands = [
,(balancesheetmode , balancesheet) ,(balancesheetmode , balancesheet)
,(cashflowmode , cashflow) ,(cashflowmode , cashflow)
,(checkmode , check) ,(checkmode , check)
,(checkdatesmode , checkdates)
,(checkdupesmode , checkdupes)
,(closemode , close) ,(closemode , close)
,(codesmode , codes) ,(codesmode , codes)
,(commoditiesmode , commodities) ,(commoditiesmode , commodities)

View File

@ -11,8 +11,8 @@ module Hledger.Cli.Commands.Check (
import Hledger import Hledger
import Hledger.Cli.CliOptions import Hledger.Cli.CliOptions
import Hledger.Cli.Commands.Checkdupes (checkdupes) import Hledger.Cli.Commands.Check.Ordereddates (journalCheckOrdereddates)
import Hledger.Cli.Commands.Checkdates (checkdates) import Hledger.Cli.Commands.Check.Uniqueleafnames (journalCheckUniqueleafnames)
import System.Console.CmdArgs.Explicit import System.Console.CmdArgs.Explicit
import Data.Either (partitionEithers) import Data.Either (partitionEithers)
import Data.Char (toUpper) import Data.Char (toUpper)
@ -82,11 +82,11 @@ runCheck copts@CliOpts{rawopts_} j (check,args) =
Commodities -> case journalCheckCommoditiesDeclared j of Commodities -> case journalCheckCommoditiesDeclared j of
Right () -> return () Right () -> return ()
Left err -> hPutStrLn stderr ("Error: "++err) >> exitFailure Left err -> hPutStrLn stderr ("Error: "++err) >> exitFailure
Ordereddates -> checkdates copts' j Ordereddates -> journalCheckOrdereddates copts' j
Payees -> case journalCheckPayeesDeclared j of Payees -> case journalCheckPayeesDeclared j of
Right () -> return () Right () -> return ()
Left err -> hPutStrLn stderr ("Error: "++err) >> exitFailure Left err -> hPutStrLn stderr ("Error: "++err) >> exitFailure
Uniqueleafnames -> checkdupes copts' j Uniqueleafnames -> journalCheckUniqueleafnames j
where where
-- Hack: append the provided args to the raw opts, -- Hack: append the provided args to the raw opts,
-- in case the check can use them (like checkdates --unique). -- in case the check can use them (like checkdates --unique).

View File

@ -1,31 +1,18 @@
{-# LANGUAGE NoOverloadedStrings #-} -- prevent trouble if turned on in ghci module Hledger.Cli.Commands.Check.Ordereddates (
{-# LANGUAGE TemplateHaskell #-} journalCheckOrdereddates
)
module Hledger.Cli.Commands.Checkdates ( where
checkdatesmode
,checkdates
) where
import Hledger import Hledger
import Hledger.Cli.CliOptions import Hledger.Cli.CliOptions
import System.Console.CmdArgs.Explicit
import System.Exit import System.Exit
import Text.Printf import Text.Printf
checkdatesmode :: Mode RawOpts journalCheckOrdereddates :: CliOpts -> Journal -> IO ()
checkdatesmode = hledgerCommandMode journalCheckOrdereddates CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do
$(embedFileRelative "Hledger/Cli/Commands/Checkdates.txt")
[flagNone ["unique"] (setboolopt "unique") "require that dates are unique"]
[generalflagsgroup1]
hiddenflags
([], Just $ argsFlag "[QUERY]")
checkdates :: CliOpts -> Journal -> IO ()
checkdates CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do
let ropts = (rsOpts rspec){accountlistmode_=ALFlat} let ropts = (rsOpts rspec){accountlistmode_=ALFlat}
let ts = filter (rsQuery rspec `matchesTransaction`) $ let ts = filter (rsQuery rspec `matchesTransaction`) $
jtxns $ journalSelectingAmountFromOpts ropts j jtxns $ journalSelectingAmountFromOpts ropts j
-- pprint rawopts
let unique = boolopt "--unique" rawopts -- TEMP: it's this for hledger check dates let unique = boolopt "--unique" rawopts -- TEMP: it's this for hledger check dates
|| boolopt "unique" rawopts -- and this for hledger check-dates (for some reason) || boolopt "unique" rawopts -- and this for hledger check-dates (for some reason)
let date = transactionDateFn ropts let date = transactionDateFn ropts

View File

@ -1,8 +1,5 @@
{-# LANGUAGE TemplateHaskell #-} module Hledger.Cli.Commands.Check.Uniqueleafnames (
journalCheckUniqueleafnames
module Hledger.Cli.Commands.Checkdupes (
checkdupesmode
,checkdupes
) )
where where
@ -11,21 +8,11 @@ import Data.List
import Data.List.Extra (nubSort) import Data.List.Extra (nubSort)
import qualified Data.Text as T import qualified Data.Text as T
import Hledger import Hledger
import Hledger.Cli.CliOptions
import System.Console.CmdArgs.Explicit
import Text.Printf import Text.Printf
import System.Exit (exitFailure) import System.Exit (exitFailure)
import Control.Monad (when) import Control.Monad (when)
checkdupesmode :: Mode RawOpts journalCheckUniqueleafnames j = do
checkdupesmode = hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Checkdupes.txt")
[]
[generalflagsgroup1]
hiddenflags
([], Nothing)
checkdupes _opts j = do
let dupes = checkdupes' $ accountsNames j let dupes = checkdupes' $ accountsNames j
when (not $ null dupes) $ do when (not $ null dupes) $ do
-- XXX make output more like Checkdates.hs, Check.hs etc. -- XXX make output more like Checkdates.hs, Check.hs etc.

View File

@ -1,8 +0,0 @@
check-dates\
Check that transactions are sorted by increasing date.
With --date2, checks secondary dates instead.
With --strict, dates must also be unique.
With a query, only matched transactions' dates are checked.
Reads the default journal file, or another specified with -f.
_FLAGS

View File

@ -1,7 +0,0 @@
check-dates
Check that transactions are sorted by increasing date. With --date2,
checks secondary dates instead. With --strict, dates must also be
unique. With a query, only matched transactions' dates are checked.
Reads the default journal file, or another specified with -f.
_FLAGS

View File

@ -1,8 +0,0 @@
check-dupes\
Reports account names having the same leaf but different prefixes.
In other words, two or more leaves that are categorized differently.
Reads the default journal file, or another specified as an argument.
_FLAGS
An example: <http://stefanorodighiero.net/software/hledger-dupes.html>

View File

@ -1,8 +0,0 @@
check-dupes
Reports account names having the same leaf but different prefixes. In
other words, two or more leaves that are categorized differently. Reads
the default journal file, or another specified as an argument.
_FLAGS
An example: http://stefanorodighiero.net/software/hledger-dupes.html

View File

@ -49,8 +49,6 @@ extra-source-files:
- Hledger/Cli/Commands/Balancesheetequity.txt - Hledger/Cli/Commands/Balancesheetequity.txt
- Hledger/Cli/Commands/Cashflow.txt - Hledger/Cli/Commands/Cashflow.txt
- Hledger/Cli/Commands/Check.txt - Hledger/Cli/Commands/Check.txt
- Hledger/Cli/Commands/Checkdates.txt
- Hledger/Cli/Commands/Checkdupes.txt
- Hledger/Cli/Commands/Close.txt - Hledger/Cli/Commands/Close.txt
- Hledger/Cli/Commands/Codes.txt - Hledger/Cli/Commands/Codes.txt
- Hledger/Cli/Commands/Commodities.txt - Hledger/Cli/Commands/Commodities.txt
@ -157,8 +155,8 @@ library:
- Hledger.Cli.Commands.Balancesheetequity - Hledger.Cli.Commands.Balancesheetequity
- Hledger.Cli.Commands.Cashflow - Hledger.Cli.Commands.Cashflow
- Hledger.Cli.Commands.Check - Hledger.Cli.Commands.Check
- Hledger.Cli.Commands.Checkdates - Hledger.Cli.Commands.Check.Ordereddates
- Hledger.Cli.Commands.Checkdupes - Hledger.Cli.Commands.Check.Uniqueleafnames
- Hledger.Cli.Commands.Close - Hledger.Cli.Commands.Close
- Hledger.Cli.Commands.Codes - Hledger.Cli.Commands.Codes
- Hledger.Cli.Commands.Commodities - Hledger.Cli.Commands.Commodities

View File

@ -14,4 +14,8 @@ $ hledger -f- check ordereddates
$ hledger -f- check ordereddates $ hledger -f- check ordereddates
> /transaction date is out of order/ > /transaction date is out of order/
>=1 >=1
# XXX make it >2 # XXX
# make it >2
# With --date2, it checks secondary dates instead.
# With --strict, dates must also be unique.
# With a query, only matched transactions' dates are checked.

View File

@ -13,4 +13,9 @@ $ hledger -f- check uniqueleafnames
$ hledger -f- check uniqueleafnames $ hledger -f- check uniqueleafnames
> /a as a, b:a/ > /a as a, b:a/
>=1 >=1
# XXX make it >2; improve message # XXX
# make it >2; improve message
# Reports account names having the same leaf but different prefixes.
# In other words, two or more leaves that are categorized differently.
# Reads the default journal file, or another specified as an argument.
# An example: <http://stefanorodighiero.net/software/hledger-dupes.html>