Skip to content

Commit 9b5fcdc

Browse files
authored
fix(cli): Where's the command help? fixes #1929 (#1945)
1 parent 8840282 commit 9b5fcdc

File tree

6 files changed

+108
-310
lines changed

6 files changed

+108
-310
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ insert_final_newline = true
99
trim_trailing_whitespace = true
1010

1111
[*.{css,js}]
12-
indent_size = 2
12+
indent_size = 4
1313

1414
[*.md]
1515
trim_trailing_whitespace = false

packages/browser-sync/lib/bin.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ if (!module.parent) {
3737
runFromCli();
3838
}
3939

40+
function freshYargs() {
41+
return require("yargs")(process.argv.slice(2));
42+
}
43+
4044
function runFromCli() {
41-
const yargs = require("yargs")
45+
const yargs = freshYargs()
4246
.command("start", "Start the server")
4347
.command("init", "Create a configuration file")
4448
.command("reload", "Send a reload event over HTTP protocol")
4549
.command("recipe", "Generate the files for a recipe")
4650
.version(pkg.version)
51+
.help(false)
4752
.epilogue(
4853
[
4954
"For help running a certain command, type <command> --help",
@@ -69,15 +74,15 @@ function runFromCli() {
6974
const valid = ["start", "init", "reload", "recipe"];
7075

7176
if (valid.indexOf(command) > -1) {
72-
return handleIncoming(command, yargs.reset());
77+
return handleIncoming(command, freshYargs());
7378
}
7479

7580
if (input.length) {
76-
return handleNoCommand(argv, input, yargs);
81+
return handleNoCommand(argv, input, freshYargs());
7782
}
7883

7984
if (existsSync("index.html")) {
80-
return handleNoCommand(argv, ["."], yargs);
85+
return handleNoCommand(argv, ["."], freshYargs());
8186
}
8287

8388
yargs.showHelp();
@@ -179,7 +184,7 @@ function processStart(yargs) {
179184
.example("$0 start -s app", "- Use the App directory to serve files")
180185
.example("$0 start -p www.bbc.co.uk", "- Proxy an existing website")
181186
.default("cwd", () => process.cwd())
182-
.help().argv;
187+
.argv;
183188
}
184189

185190
/**
@@ -206,7 +211,7 @@ function handleIncoming(command, yargs) {
206211
.example("$0 reload")
207212
.example("$0 reload --port 4000")
208213
.default("cwd", () => process.cwd())
209-
.help().argv;
214+
.argv;
210215
}
211216
if (command === "recipe") {
212217
out = yargs
@@ -215,7 +220,7 @@ function handleIncoming(command, yargs) {
215220
.example("$0 recipe ls", "list the recipes")
216221
.example("$0 recipe gulp.sass", "use the gulp.sass recipe")
217222
.default("cwd", () => process.cwd())
218-
.help().argv;
223+
.argv;
219224
}
220225

221226
if (out.help) {

0 commit comments

Comments
 (0)