Skip to content

Commit

Permalink
Fixes serializing bool values in CSV output. Closes pnp#6326
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinM85 authored and waldekmastykarz committed Sep 15, 2024
1 parent 7717450 commit dc99e61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,18 @@ describe('Command', () => {
assert(actual.indexOf(JSON.stringify(commandOutput[0].property)) === -1);
});

it('correctly serialize bool values to csv output', async () => {
const command = new MockCommand1();
const commandOutput = [
{
'property1': true,
'property2': false
}
];
const actual = await command.getCsvOutput(commandOutput, { options: { output: 'csv' } });
assert.strictEqual(actual,"property1,property2\n1,0\n");
});

it('passes validation when csv output specified', async () => {
const cmd = new MockCommand2();
assert.strictEqual(await cmd.validate({ options: { output: 'csv' } }, cli.getCommandInfo(cmd)), true);
Expand Down
5 changes: 4 additions & 1 deletion src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,10 @@ export default abstract class Command {
quote: cli.getConfig().get(settingsNames.csvQuote),
quoted: cli.getSettingWithDefaultValue<boolean>(settingsNames.csvQuoted, false),
// eslint-disable-next-line camelcase
quoted_empty: cli.getSettingWithDefaultValue<boolean>(settingsNames.csvQuotedEmpty, false)
quoted_empty: cli.getSettingWithDefaultValue<boolean>(settingsNames.csvQuotedEmpty, false),
cast: {
boolean: (value: boolean) => value ? '1' : '0'
}
});
}

Expand Down

0 comments on commit dc99e61

Please sign in to comment.