@breadc/complete 0.9.7 → 1.0.0-beta.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.
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +67 -83
- package/package.json +7 -17
- package/dist/index.cjs +0 -124
- package/dist/index.d.cts +0 -5
- package/dist/index.d.ts +0 -5
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ParseError, makeTreeNode } from
|
|
1
|
+
import { ParseError, makeTreeNode } from "breadc";
|
|
2
2
|
|
|
3
|
+
//#region src/shell/powershell.ts
|
|
3
4
|
const generatePowershell = (breadc, commands, globalOptions) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const template = `using namespace System.Management.Automation
|
|
5
|
+
const bin = breadc.name;
|
|
6
|
+
return `using namespace System.Management.Automation
|
|
7
7
|
using namespace System.Management.Automation.Language
|
|
8
8
|
Register-ArgumentCompleter -Native -CommandName '${bin}' -ScriptBlock {
|
|
9
9
|
param($wordToComplete, $commandAst, $cursorPosition)
|
|
@@ -20,100 +20,84 @@ Register-ArgumentCompleter -Native -CommandName '${bin}' -ScriptBlock {
|
|
|
20
20
|
}
|
|
21
21
|
$element.Value
|
|
22
22
|
}) -join ';'
|
|
23
|
-
$completions = @(switch ($command) {${
|
|
23
|
+
$completions = @(switch ($command) {${generateSubcommands(breadc, commands, globalOptions)}
|
|
24
24
|
})
|
|
25
25
|
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
|
|
26
26
|
Sort-Object -Property ListItemText
|
|
27
27
|
}`;
|
|
28
|
-
return template;
|
|
29
28
|
};
|
|
30
29
|
function generateSubcommands(breadc, commands, globalOptions) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
...command._options.map(
|
|
53
|
-
(o) => ` [CompletionResult]::new('--${o.name}', '${o.name}', [CompletionResultType]::ParameterName, '${o.description}')`
|
|
54
|
-
),
|
|
55
|
-
...globalOptions.map(
|
|
56
|
-
(o) => ` [CompletionResult]::new('--${o.name}', '${o.name}', [CompletionResultType]::ParameterName, '${o.description}')`
|
|
57
|
-
),
|
|
58
|
-
` break`,
|
|
59
|
-
`}`
|
|
60
|
-
].map((t) => " " + t).join("\n")
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
return cases.join("\n");
|
|
30
|
+
const cases = [];
|
|
31
|
+
cases.push([
|
|
32
|
+
"",
|
|
33
|
+
`'${breadc.name}' {`,
|
|
34
|
+
...commands.map((c) => ` [CompletionResult]::new('${c._arguments[0].name}', '${c._arguments[0].name}', [CompletionResultType]::ParameterValue, '${c.description}')`),
|
|
35
|
+
...globalOptions.map((o) => ` [CompletionResult]::new('--${o.name}', '${o.name}', [CompletionResultType]::ParameterName, '${o.description}')`),
|
|
36
|
+
` break`,
|
|
37
|
+
`}`
|
|
38
|
+
].map((t) => " " + t).join("\n"));
|
|
39
|
+
for (const command of commands) {
|
|
40
|
+
const args = command._arguments.filter((a) => a.type === "const").map((a) => a.name).join(";");
|
|
41
|
+
cases.push([
|
|
42
|
+
"",
|
|
43
|
+
`'${breadc.name};${args}' {`,
|
|
44
|
+
...command._options.map((o) => ` [CompletionResult]::new('--${o.name}', '${o.name}', [CompletionResultType]::ParameterName, '${o.description}')`),
|
|
45
|
+
...globalOptions.map((o) => ` [CompletionResult]::new('--${o.name}', '${o.name}', [CompletionResultType]::ParameterName, '${o.description}')`),
|
|
46
|
+
` break`,
|
|
47
|
+
`}`
|
|
48
|
+
].map((t) => " " + t).join("\n"));
|
|
49
|
+
}
|
|
50
|
+
return cases.join("\n");
|
|
64
51
|
}
|
|
65
52
|
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/shell/index.ts
|
|
66
55
|
function generate(shell, breadc, allCommands, globalOptions) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
} else {
|
|
70
|
-
throw new ParseError(`Unsupport shell ${shell}`);
|
|
71
|
-
}
|
|
56
|
+
if (shell === "powershell") return generatePowershell(breadc, allCommands, globalOptions);
|
|
57
|
+
else throw new ParseError(`Unsupport shell ${shell}`);
|
|
72
58
|
}
|
|
73
59
|
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/complete.ts
|
|
74
62
|
function complete() {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
makeCompleteOption(breadc, allCommands, globalOptions)
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
63
|
+
return { onInit(breadc, allCommands, globalOptions) {
|
|
64
|
+
globalOptions.push(makeCompleteOption(breadc, allCommands, globalOptions));
|
|
65
|
+
} };
|
|
82
66
|
}
|
|
83
67
|
function makeCompleteOption(breadc, allCommands, globalOptions) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
};
|
|
109
|
-
return option;
|
|
68
|
+
const node = makeTreeNode({
|
|
69
|
+
next() {
|
|
70
|
+
return false;
|
|
71
|
+
},
|
|
72
|
+
finish() {
|
|
73
|
+
return (result) => {
|
|
74
|
+
const text = generate(detectShellType(result.options["shell"]), breadc, allCommands, globalOptions);
|
|
75
|
+
console.log(text);
|
|
76
|
+
return text;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
format: "-c, --complete <shell>",
|
|
82
|
+
name: "complete",
|
|
83
|
+
short: "c",
|
|
84
|
+
type: "string",
|
|
85
|
+
initial: "",
|
|
86
|
+
order: 999999998,
|
|
87
|
+
description: "Export shell complete script",
|
|
88
|
+
parse() {
|
|
89
|
+
return node;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
110
92
|
}
|
|
111
93
|
function detectShellType(shell) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
} else {
|
|
115
|
-
return shell;
|
|
116
|
-
}
|
|
94
|
+
if (!shell) return "powershell";
|
|
95
|
+
else return shell;
|
|
117
96
|
}
|
|
118
97
|
|
|
119
|
-
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/index.ts
|
|
100
|
+
var src_default = complete;
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { complete, src_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breadc/complete",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "Autocompletion generation support for Breadc",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"breadc",
|
|
@@ -24,34 +24,24 @@
|
|
|
24
24
|
"type": "module",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
-
"
|
|
28
|
-
"import": "./dist/index.mjs"
|
|
29
|
-
"types": "./dist/index.d.ts"
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"import": "./dist/index.mjs"
|
|
30
29
|
}
|
|
31
30
|
},
|
|
32
|
-
"main": "dist/index.cjs",
|
|
33
31
|
"module": "dist/index.mjs",
|
|
34
|
-
"types": "dist/index.d.
|
|
32
|
+
"types": "dist/index.d.mts",
|
|
35
33
|
"files": [
|
|
36
34
|
"dist"
|
|
37
35
|
],
|
|
38
36
|
"dependencies": {
|
|
39
37
|
"omelette": "^0.4.17"
|
|
40
38
|
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@types/node": "^20.8.7",
|
|
43
|
-
"typescript": "^5.2.2",
|
|
44
|
-
"vitest": "0.34.6",
|
|
45
|
-
"@breadc/color": "0.9.7",
|
|
46
|
-
"breadc": "0.9.7"
|
|
47
|
-
},
|
|
48
39
|
"peerDependencies": {
|
|
49
|
-
"breadc": "0.
|
|
50
|
-
"
|
|
40
|
+
"@breadc/color": "1.0.0-beta.1",
|
|
41
|
+
"breadc": "1.0.0-beta.1"
|
|
51
42
|
},
|
|
52
43
|
"scripts": {
|
|
53
|
-
"build": "
|
|
54
|
-
"format": "prettier --write src/**/*.ts test/*.ts",
|
|
44
|
+
"build": "tsdown",
|
|
55
45
|
"test": "vitest",
|
|
56
46
|
"test:ci": "vitest --run",
|
|
57
47
|
"typecheck": "tsc --noEmit"
|
package/dist/index.cjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const breadc = require('breadc');
|
|
6
|
-
|
|
7
|
-
const generatePowershell = (breadc, commands, globalOptions) => {
|
|
8
|
-
const bin = breadc.name;
|
|
9
|
-
const subcommands = generateSubcommands(breadc, commands, globalOptions);
|
|
10
|
-
const template = `using namespace System.Management.Automation
|
|
11
|
-
using namespace System.Management.Automation.Language
|
|
12
|
-
Register-ArgumentCompleter -Native -CommandName '${bin}' -ScriptBlock {
|
|
13
|
-
param($wordToComplete, $commandAst, $cursorPosition)
|
|
14
|
-
$commandElements = $commandAst.CommandElements
|
|
15
|
-
$command = @(
|
|
16
|
-
'${bin}'
|
|
17
|
-
for ($i = 1; $i -lt $commandElements.Count; $i++) {
|
|
18
|
-
$element = $commandElements[$i]
|
|
19
|
-
if ($element -isnot [StringConstantExpressionAst] -or
|
|
20
|
-
$element.StringConstantType -ne [StringConstantType]::BareWord -or
|
|
21
|
-
$element.Value.StartsWith('-') -or
|
|
22
|
-
$element.Value -eq $wordToComplete) {
|
|
23
|
-
break
|
|
24
|
-
}
|
|
25
|
-
$element.Value
|
|
26
|
-
}) -join ';'
|
|
27
|
-
$completions = @(switch ($command) {${subcommands}
|
|
28
|
-
})
|
|
29
|
-
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
|
|
30
|
-
Sort-Object -Property ListItemText
|
|
31
|
-
}`;
|
|
32
|
-
return template;
|
|
33
|
-
};
|
|
34
|
-
function generateSubcommands(breadc, commands, globalOptions) {
|
|
35
|
-
const cases = [];
|
|
36
|
-
cases.push(
|
|
37
|
-
[
|
|
38
|
-
"",
|
|
39
|
-
`'${breadc.name}' {`,
|
|
40
|
-
...commands.map(
|
|
41
|
-
(c) => ` [CompletionResult]::new('${c._arguments[0].name}', '${c._arguments[0].name}', [CompletionResultType]::ParameterValue, '${c.description}')`
|
|
42
|
-
),
|
|
43
|
-
...globalOptions.map(
|
|
44
|
-
(o) => ` [CompletionResult]::new('--${o.name}', '${o.name}', [CompletionResultType]::ParameterName, '${o.description}')`
|
|
45
|
-
),
|
|
46
|
-
` break`,
|
|
47
|
-
`}`
|
|
48
|
-
].map((t) => " " + t).join("\n")
|
|
49
|
-
);
|
|
50
|
-
for (const command of commands) {
|
|
51
|
-
const args = command._arguments.filter((a) => a.type === "const").map((a) => a.name).join(";");
|
|
52
|
-
cases.push(
|
|
53
|
-
[
|
|
54
|
-
"",
|
|
55
|
-
`'${breadc.name};${args}' {`,
|
|
56
|
-
...command._options.map(
|
|
57
|
-
(o) => ` [CompletionResult]::new('--${o.name}', '${o.name}', [CompletionResultType]::ParameterName, '${o.description}')`
|
|
58
|
-
),
|
|
59
|
-
...globalOptions.map(
|
|
60
|
-
(o) => ` [CompletionResult]::new('--${o.name}', '${o.name}', [CompletionResultType]::ParameterName, '${o.description}')`
|
|
61
|
-
),
|
|
62
|
-
` break`,
|
|
63
|
-
`}`
|
|
64
|
-
].map((t) => " " + t).join("\n")
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return cases.join("\n");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function generate(shell, breadc$1, allCommands, globalOptions) {
|
|
71
|
-
if (shell === "powershell") {
|
|
72
|
-
return generatePowershell(breadc$1, allCommands, globalOptions);
|
|
73
|
-
} else {
|
|
74
|
-
throw new breadc.ParseError(`Unsupport shell ${shell}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function complete() {
|
|
79
|
-
return {
|
|
80
|
-
onInit(breadc, allCommands, globalOptions) {
|
|
81
|
-
globalOptions.push(
|
|
82
|
-
makeCompleteOption(breadc, allCommands, globalOptions)
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
function makeCompleteOption(breadc$1, allCommands, globalOptions) {
|
|
88
|
-
const node = breadc.makeTreeNode({
|
|
89
|
-
next() {
|
|
90
|
-
return false;
|
|
91
|
-
},
|
|
92
|
-
finish() {
|
|
93
|
-
return (result) => {
|
|
94
|
-
const shell = detectShellType(result.options["shell"]);
|
|
95
|
-
const text = generate(shell, breadc$1, allCommands, globalOptions);
|
|
96
|
-
console.log(text);
|
|
97
|
-
return text;
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
const option = {
|
|
102
|
-
format: "-c, --complete <shell>",
|
|
103
|
-
name: "complete",
|
|
104
|
-
short: "c",
|
|
105
|
-
type: "string",
|
|
106
|
-
initial: "",
|
|
107
|
-
order: 999999999 - 1,
|
|
108
|
-
description: "Export shell complete script",
|
|
109
|
-
parse() {
|
|
110
|
-
return node;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
return option;
|
|
114
|
-
}
|
|
115
|
-
function detectShellType(shell) {
|
|
116
|
-
if (!shell) {
|
|
117
|
-
return "powershell";
|
|
118
|
-
} else {
|
|
119
|
-
return shell;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
exports.complete = complete;
|
|
124
|
-
exports.default = complete;
|
package/dist/index.d.cts
DELETED