fix(cli): enable usage command (#2079)

This commit is contained in:
Daniel Roe 2021-11-22 17:19:34 +00:00 committed by GitHub
parent d68318f9d5
commit 2a29c6aa1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import { cyan } from 'colorette' import { cyan } from 'colorette'
import { showHelp } from '../utils/help'
import { commands, defineNuxtCommand } from './index' import { commands, defineNuxtCommand } from './index'
export default defineNuxtCommand({ export default defineNuxtCommand({
@ -13,5 +14,8 @@ export default defineNuxtCommand({
sections.push(`Usage: ${cyan(`npx nuxi ${Object.keys(commands).join('|')} [args]`)}`) sections.push(`Usage: ${cyan(`npx nuxi ${Object.keys(commands).join('|')} [args]`)}`)
console.log(sections.join('\n\n') + '\n') console.log(sections.join('\n\n') + '\n')
// Reuse the same wording as in `-h` commands
showHelp({})
} }
}) })

View File

@ -1,5 +1,5 @@
import mri from 'mri' import mri from 'mri'
import { red, cyan } from 'colorette' import { red } from 'colorette'
import consola from 'consola' import consola from 'consola'
import { checkEngines } from './utils/engines' import { checkEngines } from './utils/engines'
import { commands, Command, NuxtCommand } from './commands' import { commands, Command, NuxtCommand } from './commands'
@ -14,23 +14,20 @@ async function _main () {
] ]
}) })
// @ts-ignore // @ts-ignore
let command = args._.shift() || 'usage' const command = args._.shift() || 'usage'
showBanner(command === 'dev' && args.clear !== false) showBanner(command === 'dev' && args.clear !== false)
if (!(command in commands)) { if (!(command in commands)) {
console.log('\n' + red('Invalid command ' + command)) console.log('\n' + red('Invalid command ' + command))
command = 'usage'
await commands.usage().then(r => r.invoke())
process.exit(1)
} }
// Check Node.js version in background // Check Node.js version in background
setTimeout(() => { checkEngines() }, 1000) setTimeout(() => { checkEngines() }, 1000)
if (command === 'usage') {
console.log(`\nUsage: ${cyan(`npx nuxi ${Object.keys(commands).join('|')} [args]`)}\n`)
process.exit(1)
}
try { try {
// @ts-ignore default.default is hotfix for #621 // @ts-ignore default.default is hotfix for #621
const cmd = await commands[command as Command]() as NuxtCommand const cmd = await commands[command as Command]() as NuxtCommand