@jinshuju/cli 0.29.1 → 0.31.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/README.md +8 -1
- package/dist/args.d.ts +20 -0
- package/dist/args.js +50 -0
- package/dist/cli.js +15 -8
- package/dist/commands/entry.js +30 -18
- package/dist/commands/field.js +177 -17
- package/dist/commands/folder.js +5 -4
- package/dist/commands/form.js +45 -0
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/index.js +16 -3
- package/dist/commands/opensearch.js +14 -1
- package/dist/commands/shared.js +31 -3
- package/dist/commands/types.d.ts +9 -0
- package/dist/generated/operations.d.ts +1 -1
- package/dist/generated/operations.js +95 -5
- package/dist/help.js +32 -1
- package/package.json +1 -1
package/dist/help.js
CHANGED
|
@@ -91,11 +91,42 @@ export function commandHelp(command, style = PLAIN) {
|
|
|
91
91
|
}
|
|
92
92
|
return `${parts.join('\n')}\n`;
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* How far a command is from what was typed after the resource: the words it
|
|
96
|
+
* shares with it count most, and the edits that turn one word into the other
|
|
97
|
+
* break ties. `artifact get <id>` is nearest `artifact share get`, `field rmove`
|
|
98
|
+
* nearest `field remove`.
|
|
99
|
+
*/
|
|
100
|
+
function distanceTo(command, words) {
|
|
101
|
+
const wanted = command.path.slice(1);
|
|
102
|
+
const typed = words.slice(1, 1 + Math.max(wanted.length, 1));
|
|
103
|
+
const shared = wanted.filter((word) => typed.includes(word)).length;
|
|
104
|
+
const edits = wanted.reduce((sum, word, index) => sum + editDistance(word, typed[index] ?? ''), 0);
|
|
105
|
+
return edits - 100 * shared;
|
|
106
|
+
}
|
|
107
|
+
function editDistance(a, b) {
|
|
108
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
109
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
110
|
+
const current = [i];
|
|
111
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
112
|
+
current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
113
|
+
}
|
|
114
|
+
previous = current;
|
|
115
|
+
}
|
|
116
|
+
return previous[b.length];
|
|
117
|
+
}
|
|
94
118
|
/** What the caller typed that matched nothing, and the nearest things that do. */
|
|
95
119
|
export function unknownCommandHelp(words, commands = COMMANDS, style = PLAIN) {
|
|
96
120
|
const typed = words.join(' ');
|
|
97
121
|
const resource = words[0];
|
|
98
|
-
|
|
122
|
+
// Nearest first: a resource has more commands than the list shows, and the one
|
|
123
|
+
// meant used to be cut off whenever it was declared late.
|
|
124
|
+
const siblings = commands
|
|
125
|
+
.filter((command) => command.path[0] === resource)
|
|
126
|
+
.map((command, order) => ({ command, order, distance: distanceTo(command, words) }))
|
|
127
|
+
.sort((a, b) => a.distance - b.distance || a.order - b.order)
|
|
128
|
+
.slice(0, 10)
|
|
129
|
+
.map(({ command }) => command);
|
|
99
130
|
return [
|
|
100
131
|
`Unknown command: jinshuju ${typed}`,
|
|
101
132
|
...(siblings.length > 0
|