Skip to content

Commit 3c0c6d7

Browse files
committed
feat(CLI): Exit with 1 when diff is not empty.
To make it easier to use the diff command in scripts and CI and to align its API with POSIX diff and diffs on most systems exit with 1 when the diff is not empty. Keep exiting with 0 when it is. Fixes #66.
1 parent 8f9b344 commit 3c0c6d7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

playground/__tests__/cli.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ describe('Test the config-sync CLI', () => {
2626
const { stdout } = await exec('yarn cs diff');
2727
expect(stdout).toContain('No differences between DB and sync directory');
2828
});
29+
test('Non-empty diff returns 1', async () => {
30+
await exec('rm -rf config/sync/admin-role.strapi-author.json');
31+
// Work around Jest not supporting custom error matching.
32+
// https://github.com/facebook/jest/issues/8140
33+
let error;
34+
try {
35+
await exec('yarn cs diff');
36+
} catch(e) {
37+
error = e;
38+
}
39+
expect(error).toHaveProperty('code', 1);
40+
});
2941
});

server/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ program
269269
{ color: true },
270270
));
271271

272-
process.exit(0);
272+
process.exit(1);
273273
}
274274

275275
// Init table.
@@ -283,7 +283,7 @@ program
283283
// Print table.
284284
console.log(table.toString());
285285

286-
process.exit(0);
286+
process.exit(1);
287287
});
288288

289289
program.parseAsync(process.argv);

0 commit comments

Comments
 (0)