Skip to content

Commit f7982d3

Browse files
fastfrwrdjimthedev
authored andcommittedApr 19, 2019
fix(cli): allow argv to be overridden in bootstrap (#621)
A consumer's CLI has extra arguments, allowing argv to be overridden without mutating the process.argv array directly would be useful.
1 parent 26533fc commit f7982d3

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed
 

‎src/cli/commitizen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export {
1212
* This is the main cli entry point.
1313
* environment may be used for debugging.
1414
*/
15-
function bootstrap (environment = {}) {
15+
function bootstrap (environment = {}, argv = process.argv) {
1616

1717
// Get cli args
18-
let rawGitArgs = process.argv.slice(2, process.argv.length);
18+
let rawGitArgs = argv.slice(2, argv.length);
1919

2020
// Parse the args
2121
let parsedArgs = parse(rawGitArgs);

‎src/cli/git-cz.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export {
99
* This is the main cli entry point.
1010
* environment may be used for debugging.
1111
*/
12-
function bootstrap (environment = {}) {
12+
function bootstrap (environment = {}, argv = process.argv) {
1313

1414
// Get cli args
15-
let rawGitArgs = process.argv.slice(2, process.argv.length);
15+
let rawGitArgs = argv.slice(2, argv.length);
1616

1717
let adapterConfig = environment.config || configLoader.load();
1818

‎test/tests/cli.js

+7
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,12 @@ describe('git-cz', () => {
5757
});
5858
});
5959
});
60+
61+
describe('when argv is overridden', () => {
62+
it('uses the overridden argv', () => {
63+
bootstrap({}, ['node', 'git-cz', 'index.js']);
64+
expect(fakeStrategies.git.args[0][0][0]).to.equal('index.js');
65+
});
66+
})
6067
});
6168
});

0 commit comments

Comments
 (0)
Please sign in to comment.