@clerc/plugin-completions 0.26.0 → 0.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/dist/index.mjs +0 -63
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-completions",
3
- "version": "0.26.0",
3
+ "version": "0.27.1",
4
4
  "author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
5
5
  "description": "Clerc plugin completions",
6
6
  "keywords": [
@@ -27,11 +27,11 @@
27
27
  "exports": {
28
28
  ".": {
29
29
  "types": "./dist/index.d.ts",
30
- "import": "./dist/index.mjs"
30
+ "import": "./dist/index.js"
31
31
  }
32
32
  },
33
33
  "main": "dist/index.js",
34
- "module": "dist/index.mjs",
34
+ "module": "dist/index.js",
35
35
  "types": "dist/index.d.ts",
36
36
  "typesVersions": {
37
37
  "*": {
@@ -51,8 +51,8 @@
51
51
  "@clerc/core": "*"
52
52
  },
53
53
  "devDependencies": {
54
- "@clerc/core": "0.26.0",
55
- "@clerc/utils": "0.26.0"
54
+ "@clerc/core": "0.27.1",
55
+ "@clerc/utils": "0.27.1"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "puild --minify",
package/dist/index.mjs DELETED
@@ -1,63 +0,0 @@
1
- import{definePlugin as p}from"@clerc/core";const c=e=>`
2
- ${e})
3
- cmd+="__${e}"
4
- ;;`,$=e=>{const{cli:n}=e,{_name:t,_commands:o}=n;return`_${t}() {
5
- local i cur prev opts cmds
6
- COMPREPLY=()
7
- cur="\${COMP_WORDS[COMP_CWORD]}"
8
- prev="\${COMP_WORDS[COMP_CWORD-1]}"
9
- cmd=""
10
- opts=""
11
-
12
- for i in \${COMP_WORDS[@]}
13
- do
14
- case "\${i}" in
15
- "$1")
16
- cmd="${t}"
17
- ;;
18
- ${Object.keys(o).map(c).join("")}
19
- *)
20
- ;;
21
- esac
22
- done
23
- }
24
-
25
- complete -F _${t} -o bashdefault -o default ${t}
26
- `},i=e=>e.replace(/([A-Z])/g,(n,t)=>`-${t.toLowerCase()}`),r=e=>e.length<=1?`-${e}`:`--${i(e)}`,l="(No Description)",u=e=>`[CompletionResult]::new('${e.name}', '${e.name}', [CompletionResultType]::ParameterValue, '${e.description}')`,d=e=>Object.entries(e.flags||{}).map(([n,t])=>{const o=[`[CompletionResult]::new('${r(n)}', '${i(n)}', [CompletionResultType]::ParameterName, '${e.flags[n].description||l}')`];return t!=null&&t.alias&&o.push(`[CompletionResult]::new('${r(t.alias)}', '${t.alias}', [CompletionResultType]::ParameterName, '${e.flags[n].description||l}')`),o.join(`
27
- `)}).join(`
28
- `),C=e=>{const{cli:n}=e,{_name:t,_commands:o}=n;return`using namespace System.Management.Automation
29
- using namespace System.Management.Automation.Language
30
-
31
- Register-ArgumentCompleter -Native -CommandName '${t}' -ScriptBlock {
32
- param($wordToComplete, $commandAst, $cursorPosition)
33
-
34
- $commandElements = $commandAst.CommandElements
35
- $command = @(
36
- '${t}'
37
- for ($i = 1; $i -lt $commandElements.Count; $i++) {
38
- $element = $commandElements[$i]
39
- if ($element -isnot [StringConstantExpressionAst] -or
40
- $element.StringConstantType -ne [StringConstantType]::BareWord -or
41
- $element.Value.StartsWith('-') -or
42
- $element.Value -eq $wordToComplete) {
43
- break
44
- }
45
- $element.Value
46
- }) -join ';'
47
-
48
- $completions = @(switch ($command) {
49
- '${t}' {
50
- ${Object.entries(o).map(([s,m])=>u(m)).join(`
51
- `)}
52
- break
53
- }
54
- ${Object.entries(o).map(([s,m])=>`'${t};${s.split(" ").join(";")}' {
55
- ${d(m)}
56
- break
57
- }`).join(`
58
- `)}
59
- })
60
-
61
- $completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
62
- Sort-Object -Property ListItemText
63
- }`},a={bash:$,pwsh:C},g=(e={})=>p({setup:n=>{const{command:t=!0}=e;return t&&(n=n.command("completions","Print shell completions to stdout",{flags:{shell:{description:"Shell type",type:String,default:""}},parameters:["[shell]"]}).on("completions",o=>{if(!n._name)throw new Error("CLI name is not defined!");const s=String(o.parameters.shell||o.flags.shell);if(!s)throw new Error("Missing shell name");if(s in a)process.stdout.write(a[s](o));else throw new Error(`No such shell: ${s}`)})),n}});export{g as completionsPlugin};