Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Where's the command help? fixes #1929 #1945

Merged
merged 1 commit into from Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
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
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