diff --git a/messages/data.export.md b/messages/data.export.md index 377fb73..8242790 100644 --- a/messages/data.export.md +++ b/messages/data.export.md @@ -18,6 +18,6 @@ path to data plan file API Type to use -# flags.excludenullfields.summary +# flags.exclude-null-fields.summary Exclude null fields from exported JSON files diff --git a/src/commands/texei/data/export.ts b/src/commands/texei/data/export.ts index c12effd..83d5f54 100644 --- a/src/commands/texei/data/export.ts +++ b/src/commands/texei/data/export.ts @@ -62,10 +62,9 @@ export default class Export extends SfCommand { options: ['rest', 'bulk'], default: 'rest', }), - // new flag to exclude null fields - excludenullfields: Flags.boolean({ + 'exclude-null-fields': Flags.boolean({ char: 'e', - summary: messages.getMessage('flags.excludenullfields.summary'), + summary: messages.getMessage('flags.exclude-null-fields.summary'), default: false, }), // loglevel is a no-op, but this flag is added to avoid breaking scripts and warn users who are using it @@ -312,7 +311,11 @@ export default class Export extends SfCommand { const recordFile: any = {}; recordFile.attributes = objectAttributes; - recordFile.records = recordResults.map((record) => removeNullFields(record, flags.excludenullfields)); + if (flags['exclude-null-fields'] === true) { + recordFile.records = recordResults.map((record) => removeNullFields(record)); + } else { + recordFile.records = recordResults; + } // eslint-disable-next-line @typescript-eslint/no-unsafe-return return recordFile; @@ -428,11 +431,7 @@ export default class Export extends SfCommand { } // add function to remove null values from object -function removeNullFields(record: { [key: string]: any }, excludeNullFields: boolean): { [key: string]: any } { - if (!excludeNullFields) { - return record; - } - +function removeNullFields(record: { [key: string]: any }): { [key: string]: any } { const filteredRecord: { [key: string]: any } = {}; for (const key in record) { if (record[key] !== null) {