Comparing version 5.3.2 to 5.3.3
@@ -109,9 +109,20 @@ "use strict"; | ||
} | ||
getCSVRow(d) { | ||
const values = this.columns.map(col => d[col.key] || ''); | ||
const needToBeEscapedForCsv = (e) => { | ||
// CSV entries containing line breaks, comma or double quotes | ||
// as specified in https://tools.ietf.org/html/rfc4180#section-2 | ||
return e.includes('"') || e.includes('\n') || e.includes('\r\n') || e.includes('\r') || e.includes(','); | ||
}; | ||
const lineToBeEscaped = values.find(needToBeEscapedForCsv); | ||
return values.map(e => lineToBeEscaped ? `"${e.replace('"', '""')}"` : e); | ||
} | ||
outputCSV() { | ||
// tslint:disable-next-line:no-this-assignment | ||
const { data, columns, options } = this; | ||
options.printLine(columns.map(c => c.header).join(',')); | ||
if (!options['no-header']) { | ||
options.printLine(columns.map(c => c.header).join(',')); | ||
} | ||
data.forEach((d) => { | ||
let row = []; | ||
columns.forEach(col => row.push(d[col.key] || '')); | ||
const row = this.getCSVRow(d); | ||
options.printLine(row.join(',')); | ||
@@ -235,3 +246,3 @@ }); | ||
filter: command_1.flags.string({ description: 'filter property by partial string matching, ex: name=foo' }), | ||
csv: command_1.flags.boolean({ exclusive: ['no-truncate', 'no-header'], description: 'output is csv format' }), | ||
csv: command_1.flags.boolean({ exclusive: ['no-truncate'], description: 'output is csv format' }), | ||
extended: command_1.flags.boolean({ exclusive: ['columns'], char: 'x', description: 'show extra columns' }), | ||
@@ -238,0 +249,0 @@ 'no-truncate': command_1.flags.boolean({ exclusive: ['csv'], description: 'do not truncate output to fit screen' }), |
{ | ||
"name": "cli-ux", | ||
"description": "cli IO utilities", | ||
"version": "5.3.2", | ||
"version": "5.3.3", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/oclif/cli-ux/issues", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89220
1777