@clerc/plugin-completions 0.3.4 → 0.5.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.cjs +5 -4
- package/dist/index.mjs +6 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -37,14 +37,15 @@ complete -F _${name} -o bashdefault -o default ${name}
|
|
|
37
37
|
`;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
const NO_DESCRIPTION = "(No Description)";
|
|
40
41
|
const getCompletionValue = (command) => `[CompletionResult]::new('${command.name}', '${command.name}', [CompletionResultType]::ParameterValue, '${command.description}')`;
|
|
41
42
|
const getCompletionFlag = (command) => {
|
|
42
43
|
return Object.entries(command.flags || {}).map(([flagName, flag]) => {
|
|
43
|
-
const gen = [`[CompletionResult]::new('${utils.gracefulFlagName(flagName)}', '${flagName}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description ||
|
|
44
|
+
const gen = [`[CompletionResult]::new('${utils.gracefulFlagName(flagName)}', '${flagName}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description || NO_DESCRIPTION}')`];
|
|
44
45
|
if (flag == null ? void 0 : flag.alias) {
|
|
45
46
|
const arrayAlias = utils.mustArray(flag.alias);
|
|
46
47
|
gen.push(
|
|
47
|
-
...arrayAlias.map((n) => `[CompletionResult]::new('${utils.gracefulFlagName(n)}', '${n}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description ||
|
|
48
|
+
...arrayAlias.map((n) => `[CompletionResult]::new('${utils.gracefulFlagName(n)}', '${n}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description || NO_DESCRIPTION}')`)
|
|
48
49
|
);
|
|
49
50
|
}
|
|
50
51
|
return gen.join("\n ");
|
|
@@ -78,7 +79,7 @@ Register-ArgumentCompleter -Native -CommandName '${name}' -ScriptBlock {
|
|
|
78
79
|
${Object.entries(commands).map(([_, command]) => getCompletionValue(command)).join("\n ")}
|
|
79
80
|
break
|
|
80
81
|
}
|
|
81
|
-
${Object.entries(commands).map(([commandName, command]) => `'${name};${commandName}' {
|
|
82
|
+
${Object.entries(commands).map(([commandName, command]) => `'${name};${commandName.split(" ").join(";")}' {
|
|
82
83
|
${getCompletionFlag(command)}
|
|
83
84
|
break
|
|
84
85
|
}`).join("\n ")}
|
|
@@ -116,7 +117,7 @@ const completionsPlugin = (options = {}) => clerc.definePlugin({
|
|
|
116
117
|
if (shell in completionMap) {
|
|
117
118
|
console.log(completionMap[shell](ctx));
|
|
118
119
|
} else {
|
|
119
|
-
throw new
|
|
120
|
+
throw new Error(`No such shell: ${shell}`);
|
|
120
121
|
}
|
|
121
122
|
});
|
|
122
123
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { definePlugin
|
|
1
|
+
import { definePlugin } from 'clerc';
|
|
2
2
|
import { gracefulFlagName, mustArray } from '@clerc/utils';
|
|
3
3
|
|
|
4
4
|
const generateCommandCompletion = (name) => `
|
|
@@ -33,14 +33,15 @@ complete -F _${name} -o bashdefault -o default ${name}
|
|
|
33
33
|
`;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
const NO_DESCRIPTION = "(No Description)";
|
|
36
37
|
const getCompletionValue = (command) => `[CompletionResult]::new('${command.name}', '${command.name}', [CompletionResultType]::ParameterValue, '${command.description}')`;
|
|
37
38
|
const getCompletionFlag = (command) => {
|
|
38
39
|
return Object.entries(command.flags || {}).map(([flagName, flag]) => {
|
|
39
|
-
const gen = [`[CompletionResult]::new('${gracefulFlagName(flagName)}', '${flagName}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description ||
|
|
40
|
+
const gen = [`[CompletionResult]::new('${gracefulFlagName(flagName)}', '${flagName}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description || NO_DESCRIPTION}')`];
|
|
40
41
|
if (flag == null ? void 0 : flag.alias) {
|
|
41
42
|
const arrayAlias = mustArray(flag.alias);
|
|
42
43
|
gen.push(
|
|
43
|
-
...arrayAlias.map((n) => `[CompletionResult]::new('${gracefulFlagName(n)}', '${n}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description ||
|
|
44
|
+
...arrayAlias.map((n) => `[CompletionResult]::new('${gracefulFlagName(n)}', '${n}', [CompletionResultType]::ParameterName, '${command.flags[flagName].description || NO_DESCRIPTION}')`)
|
|
44
45
|
);
|
|
45
46
|
}
|
|
46
47
|
return gen.join("\n ");
|
|
@@ -74,7 +75,7 @@ Register-ArgumentCompleter -Native -CommandName '${name}' -ScriptBlock {
|
|
|
74
75
|
${Object.entries(commands).map(([_, command]) => getCompletionValue(command)).join("\n ")}
|
|
75
76
|
break
|
|
76
77
|
}
|
|
77
|
-
${Object.entries(commands).map(([commandName, command]) => `'${name};${commandName}' {
|
|
78
|
+
${Object.entries(commands).map(([commandName, command]) => `'${name};${commandName.split(" ").join(";")}' {
|
|
78
79
|
${getCompletionFlag(command)}
|
|
79
80
|
break
|
|
80
81
|
}`).join("\n ")}
|
|
@@ -112,7 +113,7 @@ const completionsPlugin = (options = {}) => definePlugin({
|
|
|
112
113
|
if (shell in completionMap) {
|
|
113
114
|
console.log(completionMap[shell](ctx));
|
|
114
115
|
} else {
|
|
115
|
-
throw new
|
|
116
|
+
throw new Error(`No such shell: ${shell}`);
|
|
116
117
|
}
|
|
117
118
|
});
|
|
118
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-completions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin completions",
|
|
6
6
|
"keywords": [
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"clerc": "*"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@clerc/utils": "0.
|
|
47
|
-
"clerc": "0.
|
|
46
|
+
"@clerc/utils": "0.5.0",
|
|
47
|
+
"clerc": "0.5.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "puild",
|