Skip to content

Commit 1fd86ae

Browse files
committed
Don't pass bnr flags to specified command
1 parent 349b0ad commit 1fd86ae

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ using the shorter alias
126126
And for silence output, you can use `-s` or verbose `--silence` flags
127127

128128
```
129-
bnr watch-client -s
129+
bnr -s watch-client
130130
```
131131

132132
And you can use `-p` or verbose `--path` to specify a custom path of dotenv file
133133

134134
```
135-
bnr start-dev --path=/custom/path/to/your/env/vars
135+
bnr --path=/custom/path/to/your/env/vars start-dev
136136
```
137137

138138
Also use `-e` or verbose `--encoding` to specify the encoding of dotenv file
139139

140140
```
141-
bnr start-dev --encoding=base64
141+
bnr --encoding=base64 start-dev
142142
```
143143

144144
See [envdot docs](https://github.com/motdotla/dotenv) for more infomation

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env node
2-
var program = require('commander'),
3-
scriptName = process.argv[2];
2+
var program = require('commander');
43

54
program
65
.option('-e, --encoding [type]', 'Specify the encoding of dotenv file')
76
.option('-p, --path [type]', 'Specify a custom path of dotenv file')
87
.option('-s, --silent', 'silent')
98
.parse(process.argv);
9+
var scriptName = program.args[0];
1010

1111
if (!program.silent) {
1212
console.log('running better-npm-run in', process.cwd());

lib/exec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ module.exports = function exec(script, program) {
99

1010
require('dotenv').config(dotenvConfig);
1111

12-
var argv = process.argv.splice(3),
12+
var argvIndex = -1;
13+
firstArg = program.args[0];
14+
if (firstArg !== undefined) {
15+
argvIndex = process.argv.indexOf(firstArg);
16+
}
17+
var argv = argvIndex === -1 ? [] : process.argv.splice(argvIndex + 1),
1318
command = (typeof script === 'string' ? script : script.command) + ' ' + argv.join(' ');
1419

1520
script.env = script.env || {};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"scripts": {
2121
"test:env": "node index.js test:env",
2222
"test:env-extend": "TEST_ENV2=envvar node index.js test:env-extend",
23-
"test:params": "node index.js test:params --test",
23+
"test:params": "node index.js --silent test:params --test",
2424
"test:command:object": "node index.js test:command:object",
2525
"test:command:string": "node index.js test:command:string",
2626
"test:silent": "node index.js test:command:object -s && node index.js test:command:object --silent",

test/params.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
if (process.argv[2] === "--silent") {
2+
throw new Error('it should eat extra arguments');
3+
}
14
if (process.argv[2] !== "--test") {
25
throw new Error('it should accept params');
36
}

0 commit comments

Comments
 (0)