convert: convert stdin when no csv file is specified

This commit is contained in:
Simon Michael 2011-08-20 19:59:20 +00:00
parent 464d8d4bcb
commit b2e80554e6
3 changed files with 11 additions and 12 deletions

View File

@ -697,12 +697,11 @@ you will get this record:
#### Converting streams
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
file and hledger will read from stdin:
streaming a CSV file from the web or another tool. Use `-` (or nothing) as
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 -
Note that a rules file is required when streaming.
$ cat foo.csv | fixup | hledger convert --rules foo.rules
### histogram

View File

@ -86,12 +86,12 @@ type CsvRecord = [String]
-- using/creating a .rules file.
convert :: CliOpts -> IO ()
convert opts = do
let csvfile = headDef "" $ patterns_ $ reportopts_ opts
when (null csvfile) $ error' "please specify a csv data file."
let
rulesFileSpecified = isJust $ rules_file_ opts
rulesfile = rulesFileFor opts csvfile
usingStdin = csvfile == "-"
let csvfile = case headDef "" $ patterns_ $ reportopts_ opts of
"" -> "-"
s -> s
usingStdin = csvfile == "-"
rulesFileSpecified = isJust $ rules_file_ opts
rulesfile = rulesFileFor opts csvfile
when (usingStdin && (not rulesFileSpecified)) $ error' "please specify a files file when converting stdin"
csvparse <- parseCsv csvfile
let records = case csvparse of

View File

@ -168,7 +168,7 @@ addmode = (commandmode ["add"]) {
convertmode = (commandmode ["convert"]) {
modeValue = [("command","convert")]
,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 {
groupUnnamed = [
flagReq ["rules-file"] (\s opts -> Right $ setopt "rules-file" s opts) "FILE" "rules file to use (default: CSVFILE.rules)"