Skip to content

Commit

Permalink
fix(cli): Where's the command help? fixes #1929 (#1945)
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane authored Mar 15, 2022
1 parent 8840282 commit 9b5fcdc
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.{css,js}]
indent_size = 2
indent_size = 4

[*.md]
trim_trailing_whitespace = false
19 changes: 12 additions & 7 deletions packages/browser-sync/lib/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ if (!module.parent) {
runFromCli();
}

function freshYargs() {
return require("yargs")(process.argv.slice(2));
}

function runFromCli() {
const yargs = require("yargs")
const yargs = freshYargs()
.command("start", "Start the server")
.command("init", "Create a configuration file")
.command("reload", "Send a reload event over HTTP protocol")
.command("recipe", "Generate the files for a recipe")
.version(pkg.version)
.help(false)
.epilogue(
[
"For help running a certain command, type <command> --help",
Expand All @@ -69,15 +74,15 @@ function runFromCli() {
const valid = ["start", "init", "reload", "recipe"];

if (valid.indexOf(command) > -1) {
return handleIncoming(command, yargs.reset());
return handleIncoming(command, freshYargs());
}

if (input.length) {
return handleNoCommand(argv, input, yargs);
return handleNoCommand(argv, input, freshYargs());
}

if (existsSync("index.html")) {
return handleNoCommand(argv, ["."], yargs);
return handleNoCommand(argv, ["."], freshYargs());
}

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

/**
Expand All @@ -206,7 +211,7 @@ function handleIncoming(command, yargs) {
.example("$0 reload")
.example("$0 reload --port 4000")
.default("cwd", () => process.cwd())
.help().argv;
.argv;
}
if (command === "recipe") {
out = yargs
Expand All @@ -215,7 +220,7 @@ function handleIncoming(command, yargs) {
.example("$0 recipe ls", "list the recipes")
.example("$0 recipe gulp.sass", "use the gulp.sass recipe")
.default("cwd", () => process.cwd())
.help().argv;
.argv;
}

if (out.help) {
Expand Down
Loading

0 comments on commit 9b5fcdc

Please sign in to comment.