mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-21 03:08:10 +03:00
Almost separator in options
This commit is contained in:
parent
ac8841cf3b
commit
f7a61737f1
@ -158,6 +158,7 @@ data InputOpts = InputOpts {
|
|||||||
mformat_ :: Maybe StorageFormat -- ^ a file/storage format to try, unless overridden
|
mformat_ :: Maybe StorageFormat -- ^ a file/storage format to try, unless overridden
|
||||||
-- by a filename prefix. Nothing means try all.
|
-- by a filename prefix. Nothing means try all.
|
||||||
,mrules_file_ :: Maybe FilePath -- ^ a conversion rules file to use (when reading CSV)
|
,mrules_file_ :: Maybe FilePath -- ^ a conversion rules file to use (when reading CSV)
|
||||||
|
,separator_ :: Char -- ^ the separator to use (when reading CSV)
|
||||||
,aliases_ :: [String] -- ^ account name aliases to apply
|
,aliases_ :: [String] -- ^ account name aliases to apply
|
||||||
,anon_ :: Bool -- ^ do light anonymisation/obfuscation of the data
|
,anon_ :: Bool -- ^ do light anonymisation/obfuscation of the data
|
||||||
,ignore_assertions_ :: Bool -- ^ don't check balance assertions
|
,ignore_assertions_ :: Bool -- ^ don't check balance assertions
|
||||||
@ -170,13 +171,14 @@ data InputOpts = InputOpts {
|
|||||||
instance Default InputOpts where def = definputopts
|
instance Default InputOpts where def = definputopts
|
||||||
|
|
||||||
definputopts :: InputOpts
|
definputopts :: InputOpts
|
||||||
definputopts = InputOpts def def def def def def True def def
|
definputopts = InputOpts def def ',' def def def def True def def
|
||||||
|
|
||||||
rawOptsToInputOpts :: RawOpts -> InputOpts
|
rawOptsToInputOpts :: RawOpts -> InputOpts
|
||||||
rawOptsToInputOpts rawopts = InputOpts{
|
rawOptsToInputOpts rawopts = InputOpts{
|
||||||
-- files_ = map (T.unpack . stripquotes . T.pack) $ listofstringopt "file" rawopts
|
-- files_ = map (T.unpack . stripquotes . T.pack) $ listofstringopt "file" rawopts
|
||||||
mformat_ = Nothing
|
mformat_ = Nothing
|
||||||
,mrules_file_ = maybestringopt "rules-file" rawopts
|
,mrules_file_ = maybestringopt "rules-file" rawopts
|
||||||
|
,separator_ = ','
|
||||||
,aliases_ = map (T.unpack . stripquotes . T.pack) $ listofstringopt "alias" rawopts
|
,aliases_ = map (T.unpack . stripquotes . T.pack) $ listofstringopt "alias" rawopts
|
||||||
,anon_ = boolopt "anon" rawopts
|
,anon_ = boolopt "anon" rawopts
|
||||||
,ignore_assertions_ = boolopt "ignore-assertions" rawopts
|
,ignore_assertions_ = boolopt "ignore-assertions" rawopts
|
||||||
|
@ -96,7 +96,8 @@ reader = Reader
|
|||||||
parse :: InputOpts -> FilePath -> Text -> ExceptT String IO Journal
|
parse :: InputOpts -> FilePath -> Text -> ExceptT String IO Journal
|
||||||
parse iopts f t = do
|
parse iopts f t = do
|
||||||
let rulesfile = mrules_file_ iopts
|
let rulesfile = mrules_file_ iopts
|
||||||
r <- liftIO $ readJournalFromCsv rulesfile f t
|
let separator = separator_ iopts
|
||||||
|
r <- liftIO $ readJournalFromCsv separator rulesfile f t
|
||||||
case r of Left e -> throwError e
|
case r of Left e -> throwError e
|
||||||
Right j -> return $ journalNumberAndTieTransactions j
|
Right j -> return $ journalNumberAndTieTransactions j
|
||||||
-- XXX does not use parseAndFinaliseJournal like the other readers
|
-- XXX does not use parseAndFinaliseJournal like the other readers
|
||||||
@ -112,9 +113,9 @@ parse iopts f t = do
|
|||||||
-- 4. if the rules file didn't exist, create it with the default rules and filename
|
-- 4. if the rules file didn't exist, create it with the default rules and filename
|
||||||
-- 5. return the transactions as a Journal
|
-- 5. return the transactions as a Journal
|
||||||
-- @
|
-- @
|
||||||
readJournalFromCsv :: Maybe FilePath -> FilePath -> Text -> IO (Either String Journal)
|
readJournalFromCsv :: Char -> Maybe FilePath -> FilePath -> Text -> IO (Either String Journal)
|
||||||
readJournalFromCsv Nothing "-" _ = return $ Left "please use --rules-file when reading CSV from stdin"
|
readJournalFromCsv separator Nothing "-" _ = return $ Left "please use --rules-file when reading CSV from stdin"
|
||||||
readJournalFromCsv mrulesfile csvfile csvdata =
|
readJournalFromCsv separator mrulesfile csvfile csvdata =
|
||||||
handle (\e -> return $ Left $ show (e :: IOException)) $ do
|
handle (\e -> return $ Left $ show (e :: IOException)) $ do
|
||||||
let throwerr = throw.userError
|
let throwerr = throw.userError
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ readJournalFromCsv mrulesfile csvfile csvdata =
|
|||||||
records <- (either throwerr id .
|
records <- (either throwerr id .
|
||||||
dbg2 "validateCsv" . validateCsv skip .
|
dbg2 "validateCsv" . validateCsv skip .
|
||||||
dbg2 "parseCsv")
|
dbg2 "parseCsv")
|
||||||
`fmap` parseCsv ',' parsecfilename csvdata
|
`fmap` parseCsv separator parsecfilename csvdata
|
||||||
dbg1IO "first 3 csv records" $ take 3 records
|
dbg1IO "first 3 csv records" $ take 3 records
|
||||||
|
|
||||||
-- identify header lines
|
-- identify header lines
|
||||||
|
Loading…
Reference in New Issue
Block a user