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 | ||||
| 
 | ||||
| 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 | ||||
| 
 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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)" | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user