mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-26 01:33:02 +00:00
fix(cli): Fix bad docusaurus CLI behavior on for --version, -V, --help, -h (#10368)
Some checks are pending
Argos CI / take-screenshots (push) Waiting to run
Build Hash Router / Build Hash Router (push) Waiting to run
Canary Release / Publish Canary (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (18.0) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (22.4) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Waiting to run
E2E Tests / E2E — npm (push) Waiting to run
E2E Tests / E2E — pnpm (push) Waiting to run
Some checks are pending
Argos CI / take-screenshots (push) Waiting to run
Build Hash Router / Build Hash Router (push) Waiting to run
Canary Release / Publish Canary (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (18.0) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (22.4) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Waiting to run
E2E Tests / E2E — npm (push) Waiting to run
E2E Tests / E2E — pnpm (push) Waiting to run
Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
7be1feaa0a
commit
087a32971f
|
|
@ -222,7 +222,8 @@ cli
|
|||
|
||||
cli.arguments('<command>').action((cmd) => {
|
||||
cli.outputHelp();
|
||||
logger.error` Unknown command name=${cmd}.`;
|
||||
logger.error`Unknown Docusaurus CLI command name=${cmd}.`;
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// === The above is the commander configuration ===
|
||||
|
|
@ -247,24 +248,24 @@ function isInternalCommand(command) {
|
|||
);
|
||||
}
|
||||
|
||||
// process.argv always looks like this:
|
||||
// [
|
||||
// '/path/to/node',
|
||||
// '/path/to/docusaurus.mjs',
|
||||
// '<subcommand>',
|
||||
// ...subcommandArgs
|
||||
// ]
|
||||
/**
|
||||
* @param {string | undefined} command
|
||||
*/
|
||||
function isExternalCommand(command) {
|
||||
return !!(command && !isInternalCommand(command) && !command.startsWith('-'));
|
||||
}
|
||||
|
||||
// There is no subcommand
|
||||
// TODO: can we use commander to handle this case?
|
||||
if (process.argv.length < 3 || process.argv[2]?.startsWith('--')) {
|
||||
// No command? We print the help message because Commander doesn't
|
||||
// Note argv looks like this: ['../node','../docusaurus.mjs','<command>',...rest]
|
||||
if (process.argv.length < 3) {
|
||||
cli.outputHelp();
|
||||
logger.error`Please provide a Docusaurus CLI command.`;
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// There is an unrecognized subcommand
|
||||
// Let plugins extend the CLI before parsing
|
||||
if (!isInternalCommand(process.argv[2])) {
|
||||
if (isExternalCommand(process.argv[2])) {
|
||||
// TODO: in this step, we must assume default site structure because there's
|
||||
// no way to know the siteDir/config yet. Maybe the root cli should be
|
||||
// responsible for parsing these arguments?
|
||||
|
|
|
|||
Loading…
Reference in New Issue