convert: convert stdin when no csv file is specified
This commit is contained in:
parent
464d8d4bcb
commit
b2e80554e6
@ -697,12 +697,11 @@ you will get this record:
|
|||||||
#### Converting streams
|
#### Converting streams
|
||||||
|
|
||||||
The convert command also supports converting standard input if you're
|
The convert command also supports converting standard input if you're
|
||||||
streaming a CSV file from the web or another tool. Use `-` as the input
|
streaming a CSV file from the web or another tool. Use `-` (or nothing) as
|
||||||
file and hledger will read from stdin:
|
the input file and hledger will read from stdin. You must specify the
|
||||||
|
rules file in this case:
|
||||||
|
|
||||||
$ cat foo.csv | fixup | hledger convert --rules foo.rules -
|
$ cat foo.csv | fixup | hledger convert --rules foo.rules
|
||||||
|
|
||||||
Note that a rules file is required when streaming.
|
|
||||||
|
|
||||||
### histogram
|
### histogram
|
||||||
|
|
||||||
|
|||||||
@ -86,12 +86,12 @@ type CsvRecord = [String]
|
|||||||
-- using/creating a .rules file.
|
-- using/creating a .rules file.
|
||||||
convert :: CliOpts -> IO ()
|
convert :: CliOpts -> IO ()
|
||||||
convert opts = do
|
convert opts = do
|
||||||
let csvfile = headDef "" $ patterns_ $ reportopts_ opts
|
let csvfile = case headDef "" $ patterns_ $ reportopts_ opts of
|
||||||
when (null csvfile) $ error' "please specify a csv data file."
|
"" -> "-"
|
||||||
let
|
s -> s
|
||||||
rulesFileSpecified = isJust $ rules_file_ opts
|
usingStdin = csvfile == "-"
|
||||||
rulesfile = rulesFileFor opts csvfile
|
rulesFileSpecified = isJust $ rules_file_ opts
|
||||||
usingStdin = csvfile == "-"
|
rulesfile = rulesFileFor opts csvfile
|
||||||
when (usingStdin && (not rulesFileSpecified)) $ error' "please specify a files file when converting stdin"
|
when (usingStdin && (not rulesFileSpecified)) $ error' "please specify a files file when converting stdin"
|
||||||
csvparse <- parseCsv csvfile
|
csvparse <- parseCsv csvfile
|
||||||
let records = case csvparse of
|
let records = case csvparse of
|
||||||
|
|||||||
@ -168,7 +168,7 @@ addmode = (commandmode ["add"]) {
|
|||||||
convertmode = (commandmode ["convert"]) {
|
convertmode = (commandmode ["convert"]) {
|
||||||
modeValue = [("command","convert")]
|
modeValue = [("command","convert")]
|
||||||
,modeHelp = "show the specified CSV file as hledger journal entries"
|
,modeHelp = "show the specified CSV file as hledger journal entries"
|
||||||
,modeArgs = Just $ flagArg (\s opts -> Right $ setopt "args" s opts) "CSVFILE"
|
,modeArgs = Just $ flagArg (\s opts -> Right $ setopt "args" s opts) "[CSVFILE]"
|
||||||
,modeGroupFlags = Group {
|
,modeGroupFlags = Group {
|
||||||
groupUnnamed = [
|
groupUnnamed = [
|
||||||
flagReq ["rules-file"] (\s opts -> Right $ setopt "rules-file" s opts) "FILE" "rules file to use (default: CSVFILE.rules)"
|
flagReq ["rules-file"] (\s opts -> Right $ setopt "rules-file" s opts) "FILE" "rules file to use (default: CSVFILE.rules)"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user