diff --git a/MANUAL.md b/MANUAL.md index 992d81822..9d4ea005c 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -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 diff --git a/hledger/Hledger/Cli/Convert.hs b/hledger/Hledger/Cli/Convert.hs index f2adbb05a..fe11cf904 100644 --- a/hledger/Hledger/Cli/Convert.hs +++ b/hledger/Hledger/Cli/Convert.hs @@ -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 diff --git a/hledger/Hledger/Cli/Options.hs b/hledger/Hledger/Cli/Options.hs index b530de9c8..86dd775ff 100644 --- a/hledger/Hledger/Cli/Options.hs +++ b/hledger/Hledger/Cli/Options.hs @@ -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)"