-
Notifications
You must be signed in to change notification settings - Fork 98
feat(cli): add tab completions #1082
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
base: main
Are you sure you want to change the base?
Changes from all commits
a7c3e3e
3811997
05f49b1
91d73a6
2ebbd6c
911f4b4
11dd4bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
"test:dist": "node ./bin/nuxi.mjs info ./playground" | ||
}, | ||
"devDependencies": { | ||
"@bomb.sh/tab": "^0.0.5", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we also need to add to |
||
"@nuxt/kit": "^4.1.3", | ||
"@nuxt/schema": "^4.1.3", | ||
"@nuxt/test-utils": "^3.19.2", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import type { ArgsDef, CommandDef } from 'citty' | ||
import tab from '@bomb.sh/tab/citty' | ||
|
||
export async function initCompletions<T extends ArgsDef = ArgsDef>(command: CommandDef<T>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we split these up into two sets of completions?
|
||
const completion = await tab(command) | ||
|
||
const devCommand = completion.commands.get('dev') | ||
if (devCommand) { | ||
const portOption = devCommand.options.get('port') | ||
if (portOption) { | ||
portOption.handler = (complete) => { | ||
complete('3000', 'Default development port') | ||
complete('3001', 'Alternative port') | ||
complete('8080', 'Common alternative port') | ||
} | ||
} | ||
|
||
const hostOption = devCommand.options.get('host') | ||
if (hostOption) { | ||
hostOption.handler = (complete) => { | ||
complete('localhost', 'Local development') | ||
complete('0.0.0.0', 'Listen on all interfaces') | ||
complete('127.0.0.1', 'Loopback address') | ||
} | ||
} | ||
} | ||
|
||
const buildCommand = completion.commands.get('build') | ||
if (buildCommand) { | ||
const presetOption = buildCommand.options.get('preset') | ||
if (presetOption) { | ||
presetOption.handler = (complete) => { | ||
complete('node-server', 'Node.js server') | ||
complete('static', 'Static hosting') | ||
complete('cloudflare-pages', 'Cloudflare Pages') | ||
complete('vercel', 'Vercel') | ||
complete('netlify', 'Netlify') | ||
complete('aws-lambda', 'AWS Lambda') | ||
complete('azure', 'Azure') | ||
complete('firebase', 'Firebase') | ||
complete('deno-deploy', 'Deno Deploy') | ||
complete('bun', 'Bun runtime') | ||
Comment on lines
+33
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a very long list of possible providers here: I wonder if it's possible to use nitropack at build time to get this list rather than hard code any of them? |
||
} | ||
} | ||
} | ||
|
||
const initCommand = completion.commands.get('init') | ||
if (initCommand) { | ||
const templateOption = initCommand.options.get('template') | ||
if (templateOption) { | ||
templateOption.handler = (complete) => { | ||
complete('v3', 'Nuxt 3 template') | ||
complete('v4', 'Nuxt 4 template') | ||
Comment on lines
+52
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our first-party templates are available at https://github.com/nuxt/starter/tree/templates/templates. again, do you think maybe we could grab data from these at build-time? |
||
} | ||
} | ||
} | ||
|
||
const addCommand = completion.commands.get('add') | ||
if (addCommand) { | ||
const cwdOption = addCommand.options.get('cwd') | ||
if (cwdOption) { | ||
cwdOption.handler = (complete) => { | ||
complete('.', 'Current directory') | ||
} | ||
} | ||
} | ||
|
||
const logLevelCommands = ['dev', 'build', 'generate', 'preview', 'prepare'] | ||
for (const cmdName of logLevelCommands) { | ||
const cmd = completion.commands.get(cmdName) | ||
if (cmd) { | ||
const logLevelOption = cmd.options.get('logLevel') | ||
if (logLevelOption) { | ||
logLevelOption.handler = (complete) => { | ||
complete('silent', 'No logs') | ||
complete('info', 'Standard logging') | ||
complete('verbose', 'Detailed logging') | ||
} | ||
} | ||
} | ||
} | ||
|
||
return completion | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we no longer advise running
nuxi
as a cli butnuxt
directly, for examplepnpm nuxt dev
within a nuxt project.@nuxt/cli
is the package most nuxt users have installed, and it works with both thenuxi
andnuxt
binaries.nuxi
is a legacy all-dependencied-inlined version for portability, but we've chosen to use a lighter version without inlined dependencies for smaller installed size, greater security (and to dedupe deps).