File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,9 @@ cli.arguments('<command>').action((cmd) => {
218
218
logger . error ` Unknown command name=${ cmd } .` ;
219
219
} ) ;
220
220
221
+ // === The above is the commander configuration ===
222
+ // They don't start any code execution yet until cli.parse() is called below
223
+
221
224
/**
222
225
* @param {string | undefined } command
223
226
*/
@@ -237,12 +240,29 @@ function isInternalCommand(command) {
237
240
) ;
238
241
}
239
242
240
- if ( ! isInternalCommand ( process . argv . slice ( 2 ) [ 0 ] ) ) {
241
- await externalCommand ( cli ) ;
242
- }
243
+ // process.argv always looks like this:
244
+ // [
245
+ // '/path/to/node',
246
+ // '/path/to/docusaurus.mjs',
247
+ // '<subcommand>',
248
+ // ...subcommandArgs
249
+ // ]
243
250
244
- if ( ! process . argv . slice ( 2 ) . length ) {
251
+ // There is no subcommand
252
+ // TODO: can we use commander to handle this case?
253
+ if ( process . argv . length < 3 || process . argv [ 2 ] ?. startsWith ( '--' ) ) {
245
254
cli . outputHelp ( ) ;
255
+ process . exit ( 1 ) ;
256
+ }
257
+
258
+ // There is an unrecognized subcommand
259
+ // Let plugins extend the CLI before parsing
260
+ if ( ! isInternalCommand ( process . argv [ 2 ] ) ) {
261
+ // TODO: in this step, we must assume default site structure because there's
262
+ // no way to know the siteDir/config yet. Maybe the root cli should be
263
+ // responsible for parsing these arguments?
264
+ // https://github.com/facebook/docusaurus/issues/8903
265
+ await externalCommand ( cli ) ;
246
266
}
247
267
248
268
cli . parse ( process . argv ) ;
You can’t perform that action at this time.
0 commit comments