@catladder/cli 0.0.0-new-cli-b2300dd6 → 0.0.0-new-cli-51a5f8b1
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/bundles/catenv/index.js +1 -1
- package/dist/bundles/cli/index.js +45 -11
- package/dist/cli/src/cli.js +3 -3
- package/dist/cli/src/cli.js.map +1 -1
- package/dist/cli/src/completion.d.ts +2 -2
- package/dist/cli/src/completion.js +40 -6
- package/dist/cli/src/completion.js.map +1 -1
- package/dist/pipeline/src/constants.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/cli.ts +7 -2
- package/src/completion.ts +43 -6
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -188,8 +188,13 @@ const completionCmd = program
|
|
|
188
188
|
completionCmd
|
|
189
189
|
.command("zsh")
|
|
190
190
|
.description("output zsh completion script")
|
|
191
|
-
.
|
|
192
|
-
|
|
191
|
+
.option(
|
|
192
|
+
"--command <cmd>",
|
|
193
|
+
"command used to invoke the CLI (e.g. 'yarn catladder')",
|
|
194
|
+
)
|
|
195
|
+
.action((opts: { command?: string }) => {
|
|
196
|
+
const binaryName =
|
|
197
|
+
opts.command ?? process.argv[1].split("/").pop() ?? "catladder";
|
|
193
198
|
console.log(generateZshCompletionScript(binaryName));
|
|
194
199
|
});
|
|
195
200
|
|
package/src/completion.ts
CHANGED
|
@@ -142,11 +142,15 @@ async function resolveChoicesForCompletion(
|
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
144
|
* Generate the zsh completion script.
|
|
145
|
-
*
|
|
145
|
+
* Supports both direct invocation (`catladder`) and prefixed (`yarn catladder`).
|
|
146
146
|
*/
|
|
147
|
-
export function generateZshCompletionScript(
|
|
148
|
-
const
|
|
149
|
-
|
|
147
|
+
export function generateZshCompletionScript(command: string): string {
|
|
148
|
+
const parts = command.split(" ");
|
|
149
|
+
const funcName = command.replace(/[- ]/g, "_");
|
|
150
|
+
|
|
151
|
+
if (parts.length === 1) {
|
|
152
|
+
// Direct binary: catladder
|
|
153
|
+
return `
|
|
150
154
|
###-begin-${funcName}-completions-###
|
|
151
155
|
_${funcName}_completions() {
|
|
152
156
|
local -a completions
|
|
@@ -156,14 +160,47 @@ _${funcName}_completions() {
|
|
|
156
160
|
local -a cmd_words=(\${words:1:$((CURRENT-2))})
|
|
157
161
|
|
|
158
162
|
# Call the CLI's __complete command
|
|
159
|
-
completions=(\${(f)"$(${
|
|
163
|
+
completions=(\${(f)"$(${command} __complete -- "\${cmd_words[*]}" "$current_word" 2>/dev/null)"})
|
|
164
|
+
|
|
165
|
+
if [[ \${#completions[@]} -gt 0 ]]; then
|
|
166
|
+
compadd -a completions
|
|
167
|
+
fi
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
compdef _${funcName}_completions ${command}
|
|
171
|
+
###-end-${funcName}-completions-###
|
|
172
|
+
`.trim();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Multi-word command (e.g., "yarn catladder")
|
|
176
|
+
// Register on the first word (e.g., "yarn") but only activate
|
|
177
|
+
// when the subcommand matches (e.g., "catladder")
|
|
178
|
+
const prefix = parts[0];
|
|
179
|
+
const subcommand = parts.slice(1).join(" ");
|
|
180
|
+
const skipWords = parts.length; // how many words to skip before CLI args
|
|
181
|
+
|
|
182
|
+
return `
|
|
183
|
+
###-begin-${funcName}-completions-###
|
|
184
|
+
_${funcName}_completions() {
|
|
185
|
+
# Only activate when subcommand is "${subcommand}"
|
|
186
|
+
if [[ $CURRENT -le ${skipWords} ]] || [[ "\${words[2,${skipWords}]}" != "${subcommand}" ]]; then
|
|
187
|
+
return
|
|
188
|
+
fi
|
|
189
|
+
|
|
190
|
+
local -a completions
|
|
191
|
+
local current_word="\${words[$CURRENT]}"
|
|
192
|
+
|
|
193
|
+
# Words after "${command}", excluding the current word being completed
|
|
194
|
+
local -a cmd_words=(\${words:${skipWords}:$((CURRENT-${skipWords}-1))})
|
|
195
|
+
|
|
196
|
+
completions=(\${(f)"$(${command} __complete -- "\${cmd_words[*]}" "$current_word" 2>/dev/null)"})
|
|
160
197
|
|
|
161
198
|
if [[ \${#completions[@]} -gt 0 ]]; then
|
|
162
199
|
compadd -a completions
|
|
163
200
|
fi
|
|
164
201
|
}
|
|
165
202
|
|
|
166
|
-
compdef _${funcName}_completions ${
|
|
203
|
+
compdef _${funcName}_completions ${prefix}
|
|
167
204
|
###-end-${funcName}-completions-###
|
|
168
205
|
`.trim();
|
|
169
206
|
}
|