Skip to content

Commit

Permalink
fix(cli): allow argv to be overridden in bootstrap (#621)
Browse files Browse the repository at this point in the history
A consumer's CLI has extra arguments, allowing argv to be overridden without mutating the process.argv array directly would be useful.
  • Loading branch information
fastfrwrd authored and jimthedev committed Apr 19, 2019
1 parent 26533fc commit f7982d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cli/commitizen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export {
* This is the main cli entry point.
* environment may be used for debugging.
*/
function bootstrap (environment = {}) {
function bootstrap (environment = {}, argv = process.argv) {

// Get cli args
let rawGitArgs = process.argv.slice(2, process.argv.length);
let rawGitArgs = argv.slice(2, argv.length);

// Parse the args
let parsedArgs = parse(rawGitArgs);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/git-cz.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export {
* This is the main cli entry point.
* environment may be used for debugging.
*/
function bootstrap (environment = {}) {
function bootstrap (environment = {}, argv = process.argv) {

// Get cli args
let rawGitArgs = process.argv.slice(2, process.argv.length);
let rawGitArgs = argv.slice(2, argv.length);

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

Expand Down
7 changes: 7 additions & 0 deletions test/tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,12 @@ describe('git-cz', () => {
});
});
});

describe('when argv is overridden', () => {
it('uses the overridden argv', () => {
bootstrap({}, ['node', 'git-cz', 'index.js']);
expect(fakeStrategies.git.args[0][0][0]).to.equal('index.js');
});
})
});
});

0 comments on commit f7982d3

Please sign in to comment.