222
222
223
223
cli . arguments ( '<command>' ) . action ( ( cmd ) => {
224
224
cli . outputHelp ( ) ;
225
- logger . error ` Unknown command name=${ cmd } .` ;
225
+ logger . error `Unknown Docusaurus CLI command name=${ cmd } .` ;
226
+ process . exit ( 1 ) ;
226
227
} ) ;
227
228
228
229
// === The above is the commander configuration ===
@@ -247,24 +248,24 @@ function isInternalCommand(command) {
247
248
) ;
248
249
}
249
250
250
- // process.argv always looks like this:
251
- // [
252
- // '/path/to/node',
253
- // '/path/to/docusaurus.mjs',
254
- // '<subcommand>',
255
- // ...subcommandArgs
256
- // ]
251
+ /**
252
+ * @param {string | undefined } command
253
+ */
254
+ function isExternalCommand ( command ) {
255
+ return ! ! ( command && ! isInternalCommand ( command ) && ! command . startsWith ( '-' ) ) ;
256
+ }
257
257
258
- // There is no subcommand
259
- // TODO: can we use commander to handle this case?
260
- if ( process . argv . length < 3 || process . argv [ 2 ] ?. startsWith ( '--' ) ) {
258
+ // No command? We print the help message because Commander doesn't
259
+ // Note argv looks like this: ['../node','../docusaurus.mjs','<command>',...rest]
260
+ if ( process . argv . length < 3 ) {
261
261
cli . outputHelp ( ) ;
262
+ logger . error `Please provide a Docusaurus CLI command.` ;
262
263
process . exit ( 1 ) ;
263
264
}
264
265
265
266
// There is an unrecognized subcommand
266
267
// Let plugins extend the CLI before parsing
267
- if ( ! isInternalCommand ( process . argv [ 2 ] ) ) {
268
+ if ( isExternalCommand ( process . argv [ 2 ] ) ) {
268
269
// TODO: in this step, we must assume default site structure because there's
269
270
// no way to know the siteDir/config yet. Maybe the root cli should be
270
271
// responsible for parsing these arguments?
0 commit comments