forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Spec for N * Remove unnecessary array Co-authored-by: Federico Ciardi <[email protected]> * Remove unnecessary array Co-authored-by: Federico Ciardi <[email protected]> * Remove unnecessary array Co-authored-by: Federico Ciardi <[email protected]> * Rework version handling Co-authored-by: Federico Ciardi <[email protected]> * Arch argument, Insecure Dangerous, Exclude use-xz * TS Fix * fix(n): Lint errors Co-authored-by: Federico Ciardi <[email protected]> Co-authored-by: Tom <[email protected]>
- Loading branch information
1 parent
e8635dd
commit 5d0d9de
Showing
1 changed file
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import node from "./node"; | ||
|
||
const versionArg: Fig.Arg = { | ||
name: "version", | ||
suggestions: [ | ||
{ | ||
name: ["latest", "current"], | ||
description: "Newest official release", | ||
}, | ||
{ | ||
name: "lts", | ||
description: "Newest Long Term Support official release", | ||
}, | ||
{ | ||
name: "auto", | ||
description: | ||
"Read version from file: .n-node-version, .node-version, .nvmrc, or package.json", | ||
}, | ||
{ | ||
name: "engine", | ||
description: "Read version from package.json", | ||
}, | ||
], | ||
generators: { | ||
script: "n lsr --all", | ||
postProcess: function (out) { | ||
const set = new Set<string>(); | ||
const versions = out.split("\n").slice(1); | ||
for (const version of versions) { | ||
set.add(version); // 16.1.2 | ||
const splitted = version.split("."); | ||
set.add(splitted[0] + "." + splitted[1]); // 16.1 | ||
set.add(splitted[0]); // 16 | ||
} | ||
return Array.from(set).map((version) => { | ||
return { | ||
name: [version, `v${version}`], | ||
description: `Node.js ${version}`, | ||
}; | ||
}); | ||
}, | ||
}, | ||
isOptional: false, | ||
}; | ||
const optionalVersionArg: Fig.Arg = { | ||
...versionArg, | ||
isOptional: true, | ||
}; | ||
const variadicVersionArg: Fig.Arg = { | ||
...versionArg, | ||
isVariadic: true, | ||
}; | ||
|
||
const completionSpec: Fig.Spec = { | ||
name: "n", | ||
description: "Node version management", | ||
subcommands: [ | ||
{ | ||
name: ["i", "install"], | ||
description: "Install a Node.js version", | ||
args: versionArg, | ||
}, | ||
{ | ||
name: ["rm", "–"], | ||
description: "Remove a Node.js version", | ||
args: variadicVersionArg, | ||
}, | ||
{ | ||
name: "prune", | ||
description: | ||
"Remove all cached Node.js versions except the installed version", | ||
}, | ||
{ | ||
name: "doctor", | ||
description: "Display diagnostics to help resolve problems", | ||
}, | ||
{ | ||
name: "uninstall", | ||
description: "Remove the installed Node.js", | ||
}, | ||
{ | ||
name: ["ls", "list"], | ||
description: "Output downloaded versions", | ||
}, | ||
{ | ||
name: ["lsr", "ls-remote", "list-remote"], | ||
description: "Output matching versions available for download", | ||
args: versionArg, | ||
options: [ | ||
{ | ||
name: "--all", | ||
description: "ls-remote displays all matches instead of last 20", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: ["which", "bin"], | ||
description: "Output path for downloaded node version", | ||
args: versionArg, | ||
}, | ||
{ | ||
name: ["run", "use", "as"], | ||
description: "Execute downloaded Node.js version with args", | ||
args: [versionArg, ...[node.args].flat()], | ||
subcommands: node.subcommands, | ||
options: node.options, | ||
}, | ||
{ | ||
name: "exec", | ||
description: | ||
"Execute command with modified PATH, so downloaded node version and npm first", | ||
args: [ | ||
versionArg, | ||
{ | ||
name: "cmd", | ||
isCommand: true, | ||
}, | ||
{ | ||
name: "args", | ||
isVariadic: true, | ||
}, | ||
], | ||
}, | ||
], | ||
args: optionalVersionArg, | ||
options: [ | ||
{ | ||
name: ["-V", "--version"], | ||
description: "Output version of n", | ||
}, | ||
{ | ||
name: ["-h", "--help"], | ||
description: "Display help information", | ||
}, | ||
{ | ||
name: ["-p", "--preserve"], | ||
description: "Preserve npm and npx during install of Node.js", | ||
}, | ||
{ | ||
name: "--no-preserve", | ||
description: "Do not preserve npm and npx during install of Node.js", | ||
}, | ||
{ | ||
name: ["-q", "--quiet"], | ||
description: | ||
'Disable curl output. Disable log messages processing "auto" and "engine" labels.', | ||
}, | ||
{ | ||
name: ["-d", "--download"], | ||
description: "Download only", | ||
}, | ||
{ | ||
name: ["-a", "--arch"], | ||
description: "Override system architecture", | ||
args: { | ||
name: "Architecture", | ||
suggestions: [ | ||
{ name: ["x64", "x86_64"] }, | ||
{ name: ["arm64", "aarch64", "armv8l"] }, | ||
{ name: ["x86", "i386", "i686"] }, | ||
{ name: ["armv6l", "armv7l"] }, | ||
], | ||
}, | ||
}, | ||
{ | ||
name: "--insecure", | ||
description: | ||
"Turn off certificate checking for https requests (may be needed from behind a proxy server)", | ||
isDangerous: true, | ||
}, | ||
{ | ||
name: "--use-xz", | ||
description: | ||
"Override automatic detection of xz support and enable use of xz compressed node downloads.", | ||
exclusiveOn: ["--no-use-xz"], | ||
}, | ||
{ | ||
name: "--no-use-xz", | ||
description: | ||
"Override automatic detection of xz support and disable use of xz compressed node downloads.", | ||
exclusiveOn: ["--use-xz"], | ||
}, | ||
], | ||
}; | ||
|
||
export default completionSpec; |