Skip to content

Commit

Permalink
CLI option for includeEmptyRows and Readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Radchenko committed Jun 21, 2016
1 parent 5e51ba5 commit a40da1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ json2csv({ data: myData, fields: fields }, function(err, csv) {
});
```

or [use it from the CLI](https://github.com/zemirco/json2csv#command-line-interface).
or [use it from the Command Line](https://github.com/zemirco/json2csv#command-line-interface).



Expand Down Expand Up @@ -294,6 +294,7 @@ Usage: json2csv [options]
-F, --flatten Flatten nested objects
-L, --ldjson Treat the input as Line-Delimited JSON.
-p, --pretty Use only when printing to console. Logs output in pretty tables.
-a, --include-empty-rows Includes empty rows in the resulting CSV output.
```

An input file `-i` and fields `-f` are required. If no output `-o` is specified the result is logged to the console.
Expand Down
13 changes: 7 additions & 6 deletions bin/json2csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ program
.option('-F, --flatten', 'Flatten nested objects')
.option('-L, --ldjson', 'Treat the input as Line-Delimited JSON.')
.option('-p, --pretty', 'Use only when printing to console. Logs output in pretty tables.')
.option('-a, --include-empty-rows', 'Includes empty rows in the resulting CSV output.')
.parse(process.argv);

function getFields(callback) {
Expand Down Expand Up @@ -108,14 +109,14 @@ getFields(function (err, fields) {

var opts = {
data: input,
fields: fields
fields: fields,
hasCSVColumnTitle: program.header,
quotes: program.quote,
defaultValue: program.defaultValue,
flatten: program.flatten,
includeEmptyRows: program.includeEmptyRows
};

opts.hasCSVColumnTitle = program.header;
opts.quotes = program.quote;
opts.defaultValue = program.defaultValue;
opts.flatten = program.flatten;

if (program.delimiter) {
opts.del = program.delimiter;
}
Expand Down

0 comments on commit a40da1c

Please sign in to comment.