@breadc/complete 1.0.0-beta.1 → 1.0.0-beta.2

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 CHANGED
@@ -1,6 +1,6 @@
1
- import { Plugin } from "breadc";
1
+ import { ActionMiddleware } from "@breadc/core";
2
2
 
3
3
  //#region src/complete.d.ts
4
- declare function complete(): Plugin;
4
+ declare function complete(): ActionMiddleware;
5
5
  //#endregion
6
- export { complete, complete as default };
6
+ export { complete };
package/dist/index.mjs CHANGED
@@ -1,103 +1,9 @@
1
- import { ParseError, makeTreeNode } from "breadc";
2
-
3
- //#region src/shell/powershell.ts
4
- const generatePowershell = (breadc, commands, globalOptions) => {
5
- const bin = breadc.name;
6
- return `using namespace System.Management.Automation
7
- using namespace System.Management.Automation.Language
8
- Register-ArgumentCompleter -Native -CommandName '${bin}' -ScriptBlock {
9
- param($wordToComplete, $commandAst, $cursorPosition)
10
- $commandElements = $commandAst.CommandElements
11
- $command = @(
12
- '${bin}'
13
- for ($i = 1; $i -lt $commandElements.Count; $i++) {
14
- $element = $commandElements[$i]
15
- if ($element -isnot [StringConstantExpressionAst] -or
16
- $element.StringConstantType -ne [StringConstantType]::BareWord -or
17
- $element.Value.StartsWith('-') -or
18
- $element.Value -eq $wordToComplete) {
19
- break
20
- }
21
- $element.Value
22
- }) -join ';'
23
- $completions = @(switch ($command) {${generateSubcommands(breadc, commands, globalOptions)}
24
- })
25
- $completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
26
- Sort-Object -Property ListItemText
27
- }`;
28
- };
29
- function generateSubcommands(breadc, commands, globalOptions) {
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");
51
- }
52
-
53
- //#endregion
54
- //#region src/shell/index.ts
55
- function generate(shell, breadc, allCommands, globalOptions) {
56
- if (shell === "powershell") return generatePowershell(breadc, allCommands, globalOptions);
57
- else throw new ParseError(`Unsupport shell ${shell}`);
58
- }
59
-
60
- //#endregion
61
1
  //#region src/complete.ts
62
2
  function complete() {
63
- return { onInit(breadc, allCommands, globalOptions) {
64
- globalOptions.push(makeCompleteOption(breadc, allCommands, globalOptions));
65
- } };
66
- }
67
- function makeCompleteOption(breadc, allCommands, globalOptions) {
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
- }
3
+ return (context, next) => {
4
+ return next();
91
5
  };
92
6
  }
93
- function detectShellType(shell) {
94
- if (!shell) return "powershell";
95
- else return shell;
96
- }
97
-
98
- //#endregion
99
- //#region src/index.ts
100
- var src_default = complete;
101
7
 
102
8
  //#endregion
103
- export { complete, src_default as default };
9
+ export { complete };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breadc/complete",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "Autocompletion generation support for Breadc",
5
5
  "keywords": [
6
6
  "breadc",
@@ -37,13 +37,13 @@
37
37
  "omelette": "^0.4.17"
38
38
  },
39
39
  "peerDependencies": {
40
- "@breadc/color": "1.0.0-beta.1",
41
- "breadc": "1.0.0-beta.1"
40
+ "@breadc/color": "1.0.0-beta.2",
41
+ "@breadc/core": "1.0.0-beta.2"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsdown",
45
- "test": "vitest",
46
45
  "test:ci": "vitest --run",
46
+ "test": "vitest",
47
47
  "typecheck": "tsc --noEmit"
48
48
  }
49
49
  }