@clerc/plugin-completions 0.25.1 → 0.26.0
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.
- package/dist/index.js +20 -83
- package/dist/index.mjs +20 -83
- package/package.json +4 -6
package/dist/index.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
${name})
|
|
6
|
-
cmd+="__${name}"
|
|
7
|
-
;;`;
|
|
8
|
-
const getBashCompletion = (ctx) => {
|
|
9
|
-
const { cli } = ctx;
|
|
10
|
-
const { _name: name, _commands: commands } = cli;
|
|
11
|
-
return `_${name}() {
|
|
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}() {
|
|
12
5
|
local i cur prev opts cmds
|
|
13
6
|
COMPREPLY=()
|
|
14
7
|
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
@@ -20,44 +13,27 @@ const getBashCompletion = (ctx) => {
|
|
|
20
13
|
do
|
|
21
14
|
case "\${i}" in
|
|
22
15
|
"$1")
|
|
23
|
-
cmd="${
|
|
16
|
+
cmd="${t}"
|
|
24
17
|
;;
|
|
25
|
-
${Object.keys(
|
|
18
|
+
${Object.keys(o).map(c).join("")}
|
|
26
19
|
*)
|
|
27
20
|
;;
|
|
28
21
|
esac
|
|
29
22
|
done
|
|
30
23
|
}
|
|
31
24
|
|
|
32
|
-
complete -F _${
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const NO_DESCRIPTION = "(No Description)";
|
|
37
|
-
const getCompletionValue = (command) => `[CompletionResult]::new('${command.name}', '${command.name}', [CompletionResultType]::ParameterValue, '${command.description}')`;
|
|
38
|
-
const getCompletionFlag = (command) => {
|
|
39
|
-
return Object.entries(command.flags || {}).map(([flagName, flag]) => {
|
|
40
|
-
const gen = [`[CompletionResult]::new('${gracefulFlagName(flagName)}', '${kebabCase(flagName)}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description || NO_DESCRIPTION}')`];
|
|
41
|
-
if (flag == null ? void 0 : flag.alias) {
|
|
42
|
-
gen.push(
|
|
43
|
-
`[CompletionResult]::new('${gracefulFlagName(flag.alias)}', '${flag.alias}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description || NO_DESCRIPTION}')`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
return gen.join("\n ");
|
|
47
|
-
}).join("\n ");
|
|
48
|
-
};
|
|
49
|
-
const getPwshCompletion = (ctx) => {
|
|
50
|
-
const { cli } = ctx;
|
|
51
|
-
const { _name: name, _commands: commands } = cli;
|
|
52
|
-
return `using namespace System.Management.Automation
|
|
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
|
|
53
29
|
using namespace System.Management.Automation.Language
|
|
54
30
|
|
|
55
|
-
Register-ArgumentCompleter -Native -CommandName '${
|
|
31
|
+
Register-ArgumentCompleter -Native -CommandName '${t}' -ScriptBlock {
|
|
56
32
|
param($wordToComplete, $commandAst, $cursorPosition)
|
|
57
33
|
|
|
58
34
|
$commandElements = $commandAst.CommandElements
|
|
59
35
|
$command = @(
|
|
60
|
-
'${
|
|
36
|
+
'${t}'
|
|
61
37
|
for ($i = 1; $i -lt $commandElements.Count; $i++) {
|
|
62
38
|
$element = $commandElements[$i]
|
|
63
39
|
if ($element -isnot [StringConstantExpressionAst] -or
|
|
@@ -70,57 +46,18 @@ Register-ArgumentCompleter -Native -CommandName '${name}' -ScriptBlock {
|
|
|
70
46
|
}) -join ';'
|
|
71
47
|
|
|
72
48
|
$completions = @(switch ($command) {
|
|
73
|
-
'${
|
|
74
|
-
${Object.entries(
|
|
49
|
+
'${t}' {
|
|
50
|
+
${Object.entries(o).map(([s,m])=>u(m)).join(`
|
|
51
|
+
`)}
|
|
75
52
|
break
|
|
76
53
|
}
|
|
77
|
-
${Object.entries(
|
|
78
|
-
${
|
|
54
|
+
${Object.entries(o).map(([s,m])=>`'${t};${s.split(" ").join(";")}' {
|
|
55
|
+
${d(m)}
|
|
79
56
|
break
|
|
80
|
-
}`).join(
|
|
57
|
+
}`).join(`
|
|
58
|
+
`)}
|
|
81
59
|
})
|
|
82
60
|
|
|
83
61
|
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
|
|
84
62
|
Sort-Object -Property ListItemText
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const completionMap = {
|
|
89
|
-
bash: getBashCompletion,
|
|
90
|
-
pwsh: getPwshCompletion
|
|
91
|
-
};
|
|
92
|
-
const completionsPlugin = (options = {}) => definePlugin({
|
|
93
|
-
setup: (cli) => {
|
|
94
|
-
const { command = true } = options;
|
|
95
|
-
if (command) {
|
|
96
|
-
cli = cli.command("completions", "Print shell completions to stdout", {
|
|
97
|
-
flags: {
|
|
98
|
-
shell: {
|
|
99
|
-
description: "Shell type",
|
|
100
|
-
type: String,
|
|
101
|
-
default: ""
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
parameters: [
|
|
105
|
-
"[shell]"
|
|
106
|
-
]
|
|
107
|
-
}).on("completions", (ctx) => {
|
|
108
|
-
if (!cli._name) {
|
|
109
|
-
throw new Error("CLI name is not defined!");
|
|
110
|
-
}
|
|
111
|
-
const shell = String(ctx.parameters.shell || ctx.flags.shell);
|
|
112
|
-
if (!shell) {
|
|
113
|
-
throw new Error("Missing shell name");
|
|
114
|
-
}
|
|
115
|
-
if (shell in completionMap) {
|
|
116
|
-
process.stdout.write(completionMap[shell](ctx));
|
|
117
|
-
} else {
|
|
118
|
-
throw new Error(`No such shell: ${shell}`);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
return cli;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
export { completionsPlugin };
|
|
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};
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
${name})
|
|
6
|
-
cmd+="__${name}"
|
|
7
|
-
;;`;
|
|
8
|
-
const getBashCompletion = (ctx) => {
|
|
9
|
-
const { cli } = ctx;
|
|
10
|
-
const { _name: name, _commands: commands } = cli;
|
|
11
|
-
return `_${name}() {
|
|
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}() {
|
|
12
5
|
local i cur prev opts cmds
|
|
13
6
|
COMPREPLY=()
|
|
14
7
|
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
@@ -20,44 +13,27 @@ const getBashCompletion = (ctx) => {
|
|
|
20
13
|
do
|
|
21
14
|
case "\${i}" in
|
|
22
15
|
"$1")
|
|
23
|
-
cmd="${
|
|
16
|
+
cmd="${t}"
|
|
24
17
|
;;
|
|
25
|
-
${Object.keys(
|
|
18
|
+
${Object.keys(o).map(c).join("")}
|
|
26
19
|
*)
|
|
27
20
|
;;
|
|
28
21
|
esac
|
|
29
22
|
done
|
|
30
23
|
}
|
|
31
24
|
|
|
32
|
-
complete -F _${
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const NO_DESCRIPTION = "(No Description)";
|
|
37
|
-
const getCompletionValue = (command) => `[CompletionResult]::new('${command.name}', '${command.name}', [CompletionResultType]::ParameterValue, '${command.description}')`;
|
|
38
|
-
const getCompletionFlag = (command) => {
|
|
39
|
-
return Object.entries(command.flags || {}).map(([flagName, flag]) => {
|
|
40
|
-
const gen = [`[CompletionResult]::new('${gracefulFlagName(flagName)}', '${kebabCase(flagName)}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description || NO_DESCRIPTION}')`];
|
|
41
|
-
if (flag == null ? void 0 : flag.alias) {
|
|
42
|
-
gen.push(
|
|
43
|
-
`[CompletionResult]::new('${gracefulFlagName(flag.alias)}', '${flag.alias}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description || NO_DESCRIPTION}')`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
return gen.join("\n ");
|
|
47
|
-
}).join("\n ");
|
|
48
|
-
};
|
|
49
|
-
const getPwshCompletion = (ctx) => {
|
|
50
|
-
const { cli } = ctx;
|
|
51
|
-
const { _name: name, _commands: commands } = cli;
|
|
52
|
-
return `using namespace System.Management.Automation
|
|
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
|
|
53
29
|
using namespace System.Management.Automation.Language
|
|
54
30
|
|
|
55
|
-
Register-ArgumentCompleter -Native -CommandName '${
|
|
31
|
+
Register-ArgumentCompleter -Native -CommandName '${t}' -ScriptBlock {
|
|
56
32
|
param($wordToComplete, $commandAst, $cursorPosition)
|
|
57
33
|
|
|
58
34
|
$commandElements = $commandAst.CommandElements
|
|
59
35
|
$command = @(
|
|
60
|
-
'${
|
|
36
|
+
'${t}'
|
|
61
37
|
for ($i = 1; $i -lt $commandElements.Count; $i++) {
|
|
62
38
|
$element = $commandElements[$i]
|
|
63
39
|
if ($element -isnot [StringConstantExpressionAst] -or
|
|
@@ -70,57 +46,18 @@ Register-ArgumentCompleter -Native -CommandName '${name}' -ScriptBlock {
|
|
|
70
46
|
}) -join ';'
|
|
71
47
|
|
|
72
48
|
$completions = @(switch ($command) {
|
|
73
|
-
'${
|
|
74
|
-
${Object.entries(
|
|
49
|
+
'${t}' {
|
|
50
|
+
${Object.entries(o).map(([s,m])=>u(m)).join(`
|
|
51
|
+
`)}
|
|
75
52
|
break
|
|
76
53
|
}
|
|
77
|
-
${Object.entries(
|
|
78
|
-
${
|
|
54
|
+
${Object.entries(o).map(([s,m])=>`'${t};${s.split(" ").join(";")}' {
|
|
55
|
+
${d(m)}
|
|
79
56
|
break
|
|
80
|
-
}`).join(
|
|
57
|
+
}`).join(`
|
|
58
|
+
`)}
|
|
81
59
|
})
|
|
82
60
|
|
|
83
61
|
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
|
|
84
62
|
Sort-Object -Property ListItemText
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const completionMap = {
|
|
89
|
-
bash: getBashCompletion,
|
|
90
|
-
pwsh: getPwshCompletion
|
|
91
|
-
};
|
|
92
|
-
const completionsPlugin = (options = {}) => definePlugin({
|
|
93
|
-
setup: (cli) => {
|
|
94
|
-
const { command = true } = options;
|
|
95
|
-
if (command) {
|
|
96
|
-
cli = cli.command("completions", "Print shell completions to stdout", {
|
|
97
|
-
flags: {
|
|
98
|
-
shell: {
|
|
99
|
-
description: "Shell type",
|
|
100
|
-
type: String,
|
|
101
|
-
default: ""
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
parameters: [
|
|
105
|
-
"[shell]"
|
|
106
|
-
]
|
|
107
|
-
}).on("completions", (ctx) => {
|
|
108
|
-
if (!cli._name) {
|
|
109
|
-
throw new Error("CLI name is not defined!");
|
|
110
|
-
}
|
|
111
|
-
const shell = String(ctx.parameters.shell || ctx.flags.shell);
|
|
112
|
-
if (!shell) {
|
|
113
|
-
throw new Error("Missing shell name");
|
|
114
|
-
}
|
|
115
|
-
if (shell in completionMap) {
|
|
116
|
-
process.stdout.write(completionMap[shell](ctx));
|
|
117
|
-
} else {
|
|
118
|
-
throw new Error(`No such shell: ${shell}`);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
return cli;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
export { completionsPlugin };
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-completions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin completions",
|
|
6
6
|
"keywords": [
|
|
@@ -50,14 +50,12 @@
|
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@clerc/core": "*"
|
|
52
52
|
},
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"@clerc/utils": "0.25.1"
|
|
55
|
-
},
|
|
56
53
|
"devDependencies": {
|
|
57
|
-
"@clerc/core": "0.
|
|
54
|
+
"@clerc/core": "0.26.0",
|
|
55
|
+
"@clerc/utils": "0.26.0"
|
|
58
56
|
},
|
|
59
57
|
"scripts": {
|
|
60
|
-
"build": "puild",
|
|
58
|
+
"build": "puild --minify",
|
|
61
59
|
"watch": "puild --watch"
|
|
62
60
|
}
|
|
63
61
|
}
|