padrone 1.1.0 → 1.3.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/CHANGELOG.md +97 -1
- package/LICENSE +1 -1
- package/README.md +60 -30
- package/dist/args-DFEI7_G_.mjs +197 -0
- package/dist/args-DFEI7_G_.mjs.map +1 -0
- package/dist/chunk-y_GBKt04.mjs +5 -0
- package/dist/codegen/index.d.mts +305 -0
- package/dist/codegen/index.d.mts.map +1 -0
- package/dist/codegen/index.mjs +1358 -0
- package/dist/codegen/index.mjs.map +1 -0
- package/dist/completion.d.mts +64 -0
- package/dist/completion.d.mts.map +1 -0
- package/dist/completion.mjs +417 -0
- package/dist/completion.mjs.map +1 -0
- package/dist/docs/index.d.mts +34 -0
- package/dist/docs/index.d.mts.map +1 -0
- package/dist/docs/index.mjs +405 -0
- package/dist/docs/index.mjs.map +1 -0
- package/dist/formatter-XroimS3Q.d.mts +83 -0
- package/dist/formatter-XroimS3Q.d.mts.map +1 -0
- package/dist/help-CgGP7hQU.mjs +1229 -0
- package/dist/help-CgGP7hQU.mjs.map +1 -0
- package/dist/index.d.mts +120 -546
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1220 -1204
- package/dist/index.mjs.map +1 -1
- package/dist/test.d.mts +112 -0
- package/dist/test.d.mts.map +1 -0
- package/dist/test.mjs +138 -0
- package/dist/test.mjs.map +1 -0
- package/dist/types-BS7RP5Ls.d.mts +1059 -0
- package/dist/types-BS7RP5Ls.d.mts.map +1 -0
- package/dist/update-check-EbNDkzyV.mjs +146 -0
- package/dist/update-check-EbNDkzyV.mjs.map +1 -0
- package/package.json +61 -21
- package/src/args.ts +457 -0
- package/src/cli/completions.ts +29 -0
- package/src/cli/docs.ts +86 -0
- package/src/cli/doctor.ts +330 -0
- package/src/cli/index.ts +159 -0
- package/src/cli/init.ts +135 -0
- package/src/cli/link.ts +320 -0
- package/src/cli/wrap.ts +152 -0
- package/src/codegen/README.md +118 -0
- package/src/codegen/code-builder.ts +226 -0
- package/src/codegen/discovery.ts +232 -0
- package/src/codegen/file-emitter.ts +73 -0
- package/src/codegen/generators/barrel-file.ts +16 -0
- package/src/codegen/generators/command-file.ts +197 -0
- package/src/codegen/generators/command-tree.ts +124 -0
- package/src/codegen/index.ts +33 -0
- package/src/codegen/parsers/fish.ts +163 -0
- package/src/codegen/parsers/help.ts +378 -0
- package/src/codegen/parsers/merge.ts +158 -0
- package/src/codegen/parsers/zsh.ts +221 -0
- package/src/codegen/schema-to-code.ts +199 -0
- package/src/codegen/template.ts +69 -0
- package/src/codegen/types.ts +143 -0
- package/src/colorizer.ts +2 -2
- package/src/command-utils.ts +504 -0
- package/src/completion.ts +110 -97
- package/src/create.ts +1048 -308
- package/src/docs/index.ts +607 -0
- package/src/errors.ts +131 -0
- package/src/formatter.ts +195 -73
- package/src/help.ts +159 -58
- package/src/index.ts +12 -15
- package/src/interactive.ts +169 -0
- package/src/parse.ts +52 -21
- package/src/repl-loop.ts +317 -0
- package/src/runtime.ts +304 -0
- package/src/shell-utils.ts +83 -0
- package/src/test.ts +285 -0
- package/src/type-helpers.ts +10 -10
- package/src/type-utils.ts +124 -14
- package/src/types.ts +752 -154
- package/src/update-check.ts +244 -0
- package/src/wrap.ts +44 -40
- package/src/zod.d.ts +2 -2
- package/src/options.ts +0 -180
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { t as __require } from "./chunk-y_GBKt04.mjs";
|
|
2
|
+
import { i as extractSchemaMetadata } from "./args-DFEI7_G_.mjs";
|
|
3
|
+
//#region src/shell-utils.ts
|
|
4
|
+
/**
|
|
5
|
+
* Detects the current shell from environment variables and process info.
|
|
6
|
+
* @returns The detected shell type, or undefined if unknown
|
|
7
|
+
*/
|
|
8
|
+
function detectShell() {
|
|
9
|
+
if (typeof process === "undefined") return void 0;
|
|
10
|
+
const shellEnv = process.env.SHELL || "";
|
|
11
|
+
if (shellEnv.includes("zsh")) return "zsh";
|
|
12
|
+
if (shellEnv.includes("bash")) return "bash";
|
|
13
|
+
if (shellEnv.includes("fish")) return "fish";
|
|
14
|
+
if (process.env.PSModulePath || process.env.POWERSHELL_DISTRIBUTION_CHANNEL) return "powershell";
|
|
15
|
+
try {
|
|
16
|
+
const ppid = process.ppid;
|
|
17
|
+
if (ppid) {
|
|
18
|
+
const { execSync } = __require("node:child_process");
|
|
19
|
+
const processName = execSync(`ps -p ${ppid} -o comm=`, {
|
|
20
|
+
encoding: "utf-8",
|
|
21
|
+
stdio: [
|
|
22
|
+
"pipe",
|
|
23
|
+
"pipe",
|
|
24
|
+
"ignore"
|
|
25
|
+
]
|
|
26
|
+
}).trim();
|
|
27
|
+
if (processName.includes("zsh")) return "zsh";
|
|
28
|
+
if (processName.includes("bash")) return "bash";
|
|
29
|
+
if (processName.includes("fish")) return "fish";
|
|
30
|
+
}
|
|
31
|
+
} catch {}
|
|
32
|
+
}
|
|
33
|
+
function getRcFile(shell, home) {
|
|
34
|
+
const { homedir } = __require("node:os");
|
|
35
|
+
const { join } = __require("node:path");
|
|
36
|
+
const h = home ?? homedir();
|
|
37
|
+
switch (shell) {
|
|
38
|
+
case "bash": return join(h, ".bashrc");
|
|
39
|
+
case "zsh": return join(h, ".zshrc");
|
|
40
|
+
case "fish": return join(h, ".config", "fish", "config.fish");
|
|
41
|
+
case "powershell": return process.env.PROFILE || join(h, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1");
|
|
42
|
+
default: return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function escapeRegExp(str) {
|
|
46
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Writes a snippet to a shell config file using begin/end markers for idempotency.
|
|
50
|
+
* If a block with the same begin marker exists, it is replaced. Otherwise the snippet is appended.
|
|
51
|
+
*/
|
|
52
|
+
function writeToRcFile(rcFile, snippet, beginMarker, endMarker) {
|
|
53
|
+
const { existsSync, mkdirSync, readFileSync, writeFileSync } = __require("node:fs");
|
|
54
|
+
const { dirname } = __require("node:path");
|
|
55
|
+
const existing = existsSync(rcFile) ? readFileSync(rcFile, "utf-8") : "";
|
|
56
|
+
if (existing.includes(beginMarker)) {
|
|
57
|
+
const pattern = new RegExp(`${escapeRegExp(beginMarker)}[\\s\\S]*?${escapeRegExp(endMarker)}`);
|
|
58
|
+
writeFileSync(rcFile, existing.replace(pattern, snippet));
|
|
59
|
+
return {
|
|
60
|
+
file: rcFile,
|
|
61
|
+
updated: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
mkdirSync(dirname(rcFile), { recursive: true });
|
|
65
|
+
writeFileSync(rcFile, `${existing}${existing.length > 0 && !existing.endsWith("\n") ? "\n" : ""}\n${snippet}\n`);
|
|
66
|
+
return {
|
|
67
|
+
file: rcFile,
|
|
68
|
+
updated: false
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/completion.ts
|
|
73
|
+
/**
|
|
74
|
+
* Collects all commands from a program recursively.
|
|
75
|
+
*/
|
|
76
|
+
function collectAllCommands(cmd) {
|
|
77
|
+
const result = [];
|
|
78
|
+
if (cmd.commands) {
|
|
79
|
+
for (const subcmd of cmd.commands) if (!subcmd.hidden) {
|
|
80
|
+
result.push(subcmd);
|
|
81
|
+
result.push(...collectAllCommands(subcmd));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Extracts all argument names from a command's schema.
|
|
88
|
+
*/
|
|
89
|
+
function extractArguments(cmd) {
|
|
90
|
+
const argList = [];
|
|
91
|
+
if (!cmd.argsSchema) return argList;
|
|
92
|
+
try {
|
|
93
|
+
const argsMeta = cmd.meta?.fields;
|
|
94
|
+
const { aliases } = extractSchemaMetadata(cmd.argsSchema, argsMeta, cmd.meta?.autoAlias);
|
|
95
|
+
const aliasToArgument = {};
|
|
96
|
+
for (const [arg, alias] of Object.entries(aliases)) aliasToArgument[alias] = arg;
|
|
97
|
+
const jsonSchema = cmd.argsSchema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
|
|
98
|
+
if (jsonSchema.type === "object" && jsonSchema.properties) for (const [key, prop] of Object.entries(jsonSchema.properties)) {
|
|
99
|
+
const alias = Object.entries(aliases).find(([arg]) => arg === key)?.[1];
|
|
100
|
+
argList.push({
|
|
101
|
+
name: key,
|
|
102
|
+
alias,
|
|
103
|
+
isBoolean: prop?.type === "boolean"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
} catch {}
|
|
107
|
+
return argList;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Generates a Bash completion script for the program.
|
|
111
|
+
*/
|
|
112
|
+
function generateBashCompletion(program) {
|
|
113
|
+
const programName = program.name;
|
|
114
|
+
const commands = collectAllCommands(program);
|
|
115
|
+
const commandNames = commands.map((c) => c.name).join(" ");
|
|
116
|
+
const allArguments = /* @__PURE__ */ new Set();
|
|
117
|
+
allArguments.add("--help");
|
|
118
|
+
allArguments.add("--version");
|
|
119
|
+
for (const cmd of [program, ...commands]) for (const arg of extractArguments(cmd)) {
|
|
120
|
+
allArguments.add(`--${arg.name}`);
|
|
121
|
+
if (arg.alias) allArguments.add(`-${arg.alias}`);
|
|
122
|
+
}
|
|
123
|
+
const argsList = Array.from(allArguments).join(" ");
|
|
124
|
+
return `###-begin-${programName}-completion-###
|
|
125
|
+
#
|
|
126
|
+
# ${programName} command completion script
|
|
127
|
+
#
|
|
128
|
+
# Installation: ${programName} completion >> ~/.bashrc (or ~/.zshrc)
|
|
129
|
+
# Or, maybe: ${programName} completion > /usr/local/etc/bash_completion.d/${programName}
|
|
130
|
+
#
|
|
131
|
+
|
|
132
|
+
if type complete &>/dev/null; then
|
|
133
|
+
_${programName}_completion() {
|
|
134
|
+
local cur prev words cword
|
|
135
|
+
if type _get_comp_words_by_ref &>/dev/null; then
|
|
136
|
+
_get_comp_words_by_ref -n = -n @ -n : -w words -i cword
|
|
137
|
+
else
|
|
138
|
+
cword="$COMP_CWORD"
|
|
139
|
+
words=("\${COMP_WORDS[@]}")
|
|
140
|
+
fi
|
|
141
|
+
|
|
142
|
+
cur="\${words[cword]}"
|
|
143
|
+
prev="\${words[cword-1]}"
|
|
144
|
+
|
|
145
|
+
local commands="${commandNames}"
|
|
146
|
+
local args="${argsList}"
|
|
147
|
+
|
|
148
|
+
# Complete args when current word starts with -
|
|
149
|
+
if [[ "$cur" == -* ]]; then
|
|
150
|
+
COMPREPLY=($(compgen -W "$args" -- "$cur"))
|
|
151
|
+
return 0
|
|
152
|
+
fi
|
|
153
|
+
|
|
154
|
+
# Complete commands
|
|
155
|
+
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
|
|
156
|
+
}
|
|
157
|
+
complete -o bashdefault -o default -o nospace -F _${programName}_completion ${programName}
|
|
158
|
+
elif type compdef &>/dev/null; then
|
|
159
|
+
_${programName}_completion() {
|
|
160
|
+
local si=$IFS
|
|
161
|
+
local commands="${commandNames}"
|
|
162
|
+
local args="${argsList}"
|
|
163
|
+
|
|
164
|
+
if [[ "\${words[CURRENT]}" == -* ]]; then
|
|
165
|
+
compadd -- \${=args}
|
|
166
|
+
else
|
|
167
|
+
compadd -- \${=commands}
|
|
168
|
+
fi
|
|
169
|
+
IFS=$si
|
|
170
|
+
}
|
|
171
|
+
compdef _${programName}_completion ${programName}
|
|
172
|
+
elif type compctl &>/dev/null; then
|
|
173
|
+
_${programName}_completion() {
|
|
174
|
+
local commands="${commandNames}"
|
|
175
|
+
local args="${argsList}"
|
|
176
|
+
|
|
177
|
+
if [[ "\${words[CURRENT]}" == -* ]]; then
|
|
178
|
+
reply=(\${=args})
|
|
179
|
+
else
|
|
180
|
+
reply=(\${=commands})
|
|
181
|
+
fi
|
|
182
|
+
}
|
|
183
|
+
compctl -K _${programName}_completion ${programName}
|
|
184
|
+
fi
|
|
185
|
+
###-end-${programName}-completion-###`;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Generates a Zsh completion script for the program.
|
|
189
|
+
*/
|
|
190
|
+
function generateZshCompletion(program) {
|
|
191
|
+
const programName = program.name;
|
|
192
|
+
const commands = collectAllCommands(program);
|
|
193
|
+
const commandCompletions = commands.map((cmd) => {
|
|
194
|
+
const escapedDesc = (cmd.description || cmd.title || "").replace(/'/g, "'\\''").replace(/:/g, "\\:");
|
|
195
|
+
return ` '${cmd.name}:${escapedDesc}'`;
|
|
196
|
+
}).join("\n");
|
|
197
|
+
const argumentCompletions = [];
|
|
198
|
+
argumentCompletions.push(" '--help[Show help information]'");
|
|
199
|
+
argumentCompletions.push(" '--version[Show version number]'");
|
|
200
|
+
const seenArgs = new Set(["help", "version"]);
|
|
201
|
+
for (const cmd of [program, ...commands]) for (const arg of extractArguments(cmd)) {
|
|
202
|
+
if (seenArgs.has(arg.name)) continue;
|
|
203
|
+
seenArgs.add(arg.name);
|
|
204
|
+
const escapedDesc = (cmd.meta?.fields?.[arg.name]?.description || "").replace(/'/g, "'\\''").replace(/\[/g, "\\[").replace(/\]/g, "\\]");
|
|
205
|
+
if (arg.alias) argumentCompletions.push(` {-${arg.alias},--${arg.name}}'[${escapedDesc}]'`);
|
|
206
|
+
else argumentCompletions.push(` '--${arg.name}[${escapedDesc}]'`);
|
|
207
|
+
}
|
|
208
|
+
return `#compdef ${programName}
|
|
209
|
+
###-begin-${programName}-completion-###
|
|
210
|
+
#
|
|
211
|
+
# ${programName} command completion script for Zsh
|
|
212
|
+
#
|
|
213
|
+
# Installation: ${programName} completion >> ~/.zshrc
|
|
214
|
+
# Or: ${programName} completion > ~/.zsh/completions/_${programName}
|
|
215
|
+
#
|
|
216
|
+
|
|
217
|
+
_${programName}() {
|
|
218
|
+
local -a commands
|
|
219
|
+
local -a args
|
|
220
|
+
|
|
221
|
+
commands=(
|
|
222
|
+
${commandCompletions}
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
args=(
|
|
226
|
+
${argumentCompletions.join("\n")}
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
_arguments -s \\
|
|
230
|
+
$args \\
|
|
231
|
+
'1: :->command' \\
|
|
232
|
+
'*::arg:->args'
|
|
233
|
+
|
|
234
|
+
case "$state" in
|
|
235
|
+
command)
|
|
236
|
+
_describe 'command' commands
|
|
237
|
+
;;
|
|
238
|
+
esac
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
_${programName}
|
|
242
|
+
###-end-${programName}-completion-###`;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Generates a Fish completion script for the program.
|
|
246
|
+
*/
|
|
247
|
+
function generateFishCompletion(program) {
|
|
248
|
+
const programName = program.name;
|
|
249
|
+
const commands = collectAllCommands(program);
|
|
250
|
+
const lines = [
|
|
251
|
+
`###-begin-${programName}-completion-###`,
|
|
252
|
+
"#",
|
|
253
|
+
`# ${programName} command completion script for Fish`,
|
|
254
|
+
"#",
|
|
255
|
+
`# Installation: ${programName} completion > ~/.config/fish/completions/${programName}.fish`,
|
|
256
|
+
"#",
|
|
257
|
+
"",
|
|
258
|
+
`# Clear existing completions`,
|
|
259
|
+
`complete -c ${programName} -e`,
|
|
260
|
+
"",
|
|
261
|
+
"# Commands"
|
|
262
|
+
];
|
|
263
|
+
for (const cmd of commands) {
|
|
264
|
+
const escapedDesc = (cmd.description || cmd.title || "").replace(/'/g, "\\'");
|
|
265
|
+
lines.push(`complete -c ${programName} -n "__fish_use_subcommand" -a "${cmd.name}" -d '${escapedDesc}'`);
|
|
266
|
+
}
|
|
267
|
+
lines.push("");
|
|
268
|
+
lines.push("# Global arguments");
|
|
269
|
+
lines.push(`complete -c ${programName} -l help -d 'Show help information'`);
|
|
270
|
+
lines.push(`complete -c ${programName} -l version -d 'Show version number'`);
|
|
271
|
+
const seenArgs = new Set(["help", "version"]);
|
|
272
|
+
for (const cmd of [program, ...commands]) for (const arg of extractArguments(cmd)) {
|
|
273
|
+
if (seenArgs.has(arg.name)) continue;
|
|
274
|
+
seenArgs.add(arg.name);
|
|
275
|
+
const escapedDesc = (cmd.meta?.fields?.[arg.name]?.description || "").replace(/'/g, "\\'");
|
|
276
|
+
if (arg.alias) lines.push(`complete -c ${programName} -s ${arg.alias} -l ${arg.name} -d '${escapedDesc}'`);
|
|
277
|
+
else lines.push(`complete -c ${programName} -l ${arg.name} -d '${escapedDesc}'`);
|
|
278
|
+
}
|
|
279
|
+
lines.push(`###-end-${programName}-completion-###`);
|
|
280
|
+
return lines.join("\n");
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Generates a PowerShell completion script for the program.
|
|
284
|
+
*/
|
|
285
|
+
function generatePowerShellCompletion(program) {
|
|
286
|
+
const programName = program.name;
|
|
287
|
+
return `###-begin-${programName}-completion-###
|
|
288
|
+
#
|
|
289
|
+
# ${programName} command completion script for PowerShell
|
|
290
|
+
#
|
|
291
|
+
# Installation: ${programName} completion >> $PROFILE
|
|
292
|
+
#
|
|
293
|
+
|
|
294
|
+
Register-ArgumentCompleter -Native -CommandName ${programName} -ScriptBlock {
|
|
295
|
+
param($wordToComplete, $commandAst, $cursorPosition)
|
|
296
|
+
|
|
297
|
+
$commands = @(${collectAllCommands(program).map((c) => `'${c.name}'`).join(", ")})
|
|
298
|
+
$args = @('--help', '--version')
|
|
299
|
+
|
|
300
|
+
if ($wordToComplete -like '-*') {
|
|
301
|
+
$args | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
302
|
+
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
$commands | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
|
|
306
|
+
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
###-end-${programName}-completion-###`;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Generates a completion script for the specified shell.
|
|
314
|
+
*/
|
|
315
|
+
function generateCompletion(program, shell) {
|
|
316
|
+
switch (shell) {
|
|
317
|
+
case "bash": return generateBashCompletion(program);
|
|
318
|
+
case "zsh": return generateZshCompletion(program);
|
|
319
|
+
case "fish": return generateFishCompletion(program);
|
|
320
|
+
case "powershell": return generatePowerShellCompletion(program);
|
|
321
|
+
default: throw new Error(`Unsupported shell: ${shell}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Gets the installation instructions for a shell completion script.
|
|
326
|
+
*/
|
|
327
|
+
function getCompletionInstallInstructions(programName, shell) {
|
|
328
|
+
switch (shell) {
|
|
329
|
+
case "bash": return `# Add to ~/.bashrc:
|
|
330
|
+
${programName} completion bash >> ~/.bashrc
|
|
331
|
+
|
|
332
|
+
# Or install system-wide:
|
|
333
|
+
${programName} completion bash > /usr/local/etc/bash_completion.d/${programName}`;
|
|
334
|
+
case "zsh": return `# Add to ~/.zshrc:
|
|
335
|
+
${programName} completion zsh >> ~/.zshrc
|
|
336
|
+
|
|
337
|
+
# Or add to completions directory:
|
|
338
|
+
${programName} completion zsh > ~/.zsh/completions/_${programName}`;
|
|
339
|
+
case "fish": return `# Install to Fish completions:
|
|
340
|
+
${programName} completion fish > ~/.config/fish/completions/${programName}.fish`;
|
|
341
|
+
case "powershell": return `# Add to PowerShell profile:
|
|
342
|
+
${programName} completion powershell >> $PROFILE`;
|
|
343
|
+
default: return `# Run: ${programName} completion <shell>
|
|
344
|
+
# Supported shells: bash, zsh, fish, powershell`;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Generates the completion output with automatic shell detection.
|
|
349
|
+
* If shell is not specified, detects the current shell and provides instructions.
|
|
350
|
+
*/
|
|
351
|
+
function generateCompletionOutput(program, shell) {
|
|
352
|
+
const programName = program.name;
|
|
353
|
+
if (shell) return generateCompletion(program, shell);
|
|
354
|
+
const detectedShell = detectShell();
|
|
355
|
+
if (detectedShell) return `# Detected shell: ${detectedShell}
|
|
356
|
+
#
|
|
357
|
+
${getCompletionInstallInstructions(programName, detectedShell)}
|
|
358
|
+
#
|
|
359
|
+
# Or evaluate directly (temporary, for current session only):
|
|
360
|
+
# eval "$(${programName} completion ${detectedShell})"
|
|
361
|
+
|
|
362
|
+
${generateCompletion(program, detectedShell)}`;
|
|
363
|
+
return `# Shell auto-detection failed.
|
|
364
|
+
#
|
|
365
|
+
# Usage: ${programName} completion <shell>
|
|
366
|
+
#
|
|
367
|
+
# Supported shells:
|
|
368
|
+
# bash - Bash completion script
|
|
369
|
+
# zsh - Zsh completion script
|
|
370
|
+
# fish - Fish completion script
|
|
371
|
+
# powershell - PowerShell completion script
|
|
372
|
+
#
|
|
373
|
+
# Example:
|
|
374
|
+
# ${programName} completion bash >> ~/.bashrc
|
|
375
|
+
# ${programName} completion zsh >> ~/.zshrc
|
|
376
|
+
# ${programName} completion fish > ~/.config/fish/completions/${programName}.fish
|
|
377
|
+
# ${programName} completion powershell >> $PROFILE`;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Sets up shell completions by writing an eval snippet to the appropriate shell config file.
|
|
381
|
+
* Uses marker comments for idempotency — re-running replaces the existing block.
|
|
382
|
+
*/
|
|
383
|
+
function setupCompletions(programName, shell) {
|
|
384
|
+
const { existsSync, mkdirSync, writeFileSync } = __require("node:fs");
|
|
385
|
+
const { join } = __require("node:path");
|
|
386
|
+
const { homedir } = __require("node:os");
|
|
387
|
+
const beginMarker = `###-begin-${programName}-completion-###`;
|
|
388
|
+
const endMarker = `###-end-${programName}-completion-###`;
|
|
389
|
+
const snippet = buildSetupSnippet(programName, shell, beginMarker, endMarker);
|
|
390
|
+
if (shell === "fish") {
|
|
391
|
+
const completionsDir = join(homedir(), ".config", "fish", "completions");
|
|
392
|
+
const filePath = join(completionsDir, `${programName}.fish`);
|
|
393
|
+
mkdirSync(completionsDir, { recursive: true });
|
|
394
|
+
const existed = existsSync(filePath);
|
|
395
|
+
writeFileSync(filePath, `${snippet}\n`);
|
|
396
|
+
return {
|
|
397
|
+
file: filePath,
|
|
398
|
+
updated: existed
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
const rcFile = getRcFile(shell);
|
|
402
|
+
if (!rcFile) throw new Error(`Could not determine config file for ${shell}.`);
|
|
403
|
+
return writeToRcFile(rcFile, snippet, beginMarker, endMarker);
|
|
404
|
+
}
|
|
405
|
+
function buildSetupSnippet(programName, shell, beginMarker, endMarker) {
|
|
406
|
+
const evalCmd = `${programName} completion ${shell}`;
|
|
407
|
+
switch (shell) {
|
|
408
|
+
case "bash":
|
|
409
|
+
case "zsh": return `${beginMarker}\neval "$(${evalCmd})"\n${endMarker}`;
|
|
410
|
+
case "fish": return `${beginMarker}\n${evalCmd} | source\n${endMarker}`;
|
|
411
|
+
case "powershell": return `${beginMarker}\n${evalCmd} | Invoke-Expression\n${endMarker}`;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
//#endregion
|
|
415
|
+
export { detectShell, escapeRegExp, generateBashCompletion, generateCompletion, generateCompletionOutput, generateFishCompletion, generatePowerShellCompletion, generateZshCompletion, getCompletionInstallInstructions, getRcFile, setupCompletions, writeToRcFile };
|
|
416
|
+
|
|
417
|
+
//# sourceMappingURL=completion.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion.mjs","names":[],"sources":["../src/shell-utils.ts","../src/completion.ts"],"sourcesContent":["export type ShellType = 'bash' | 'zsh' | 'fish' | 'powershell';\n\n/**\n * Detects the current shell from environment variables and process info.\n * @returns The detected shell type, or undefined if unknown\n */\nexport function detectShell(): ShellType | undefined {\n if (typeof process === 'undefined') return undefined;\n\n // Method 1: Check SHELL environment variable (most common)\n const shellEnv = process.env.SHELL || '';\n if (shellEnv.includes('zsh')) return 'zsh';\n if (shellEnv.includes('bash')) return 'bash';\n if (shellEnv.includes('fish')) return 'fish';\n\n // Method 2: Check Windows-specific shells\n if (process.env.PSModulePath || process.env.POWERSHELL_DISTRIBUTION_CHANNEL) {\n return 'powershell';\n }\n\n // Method 3: Check parent process on Unix-like systems\n try {\n const ppid = process.ppid;\n if (ppid) {\n const { execSync } = require('node:child_process') as typeof import('node:child_process');\n const processName = execSync(`ps -p ${ppid} -o comm=`, {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'ignore'],\n }).trim();\n\n if (processName.includes('zsh')) return 'zsh';\n if (processName.includes('bash')) return 'bash';\n if (processName.includes('fish')) return 'fish';\n }\n } catch {\n // Ignore errors (e.g., ps not available)\n }\n\n return undefined;\n}\n\nexport function getRcFile(shell: ShellType, home?: string): string | null {\n const { homedir } = require('node:os') as typeof import('node:os');\n const { join } = require('node:path') as typeof import('node:path');\n const h = home ?? homedir();\n switch (shell) {\n case 'bash':\n return join(h, '.bashrc');\n case 'zsh':\n return join(h, '.zshrc');\n case 'fish':\n return join(h, '.config', 'fish', 'config.fish');\n case 'powershell':\n return process.env.PROFILE || join(h, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1');\n default:\n return null;\n }\n}\n\nexport function escapeRegExp(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\n/**\n * Writes a snippet to a shell config file using begin/end markers for idempotency.\n * If a block with the same begin marker exists, it is replaced. Otherwise the snippet is appended.\n */\nexport function writeToRcFile(rcFile: string, snippet: string, beginMarker: string, endMarker: string): { file: string; updated: boolean } {\n const { existsSync, mkdirSync, readFileSync, writeFileSync } = require('node:fs') as typeof import('node:fs');\n const { dirname } = require('node:path') as typeof import('node:path');\n const existing = existsSync(rcFile) ? readFileSync(rcFile, 'utf-8') : '';\n\n if (existing.includes(beginMarker)) {\n const pattern = new RegExp(`${escapeRegExp(beginMarker)}[\\\\s\\\\S]*?${escapeRegExp(endMarker)}`);\n writeFileSync(rcFile, existing.replace(pattern, snippet));\n return { file: rcFile, updated: true };\n }\n\n mkdirSync(dirname(rcFile), { recursive: true });\n const separator = existing.length > 0 && !existing.endsWith('\\n') ? '\\n' : '';\n writeFileSync(rcFile, `${existing}${separator}\\n${snippet}\\n`);\n return { file: rcFile, updated: false };\n}\n","import { extractSchemaMetadata } from './args.ts';\nimport { detectShell, getRcFile, type ShellType, writeToRcFile } from './shell-utils.ts';\nimport type { AnyPadroneCommand } from './types.ts';\n\nexport { detectShell, escapeRegExp, getRcFile, type ShellType, writeToRcFile } from './shell-utils.ts';\n\n/**\n * Collects all commands from a program recursively.\n */\nfunction collectAllCommands(cmd: AnyPadroneCommand): AnyPadroneCommand[] {\n const result: AnyPadroneCommand[] = [];\n\n if (cmd.commands) {\n for (const subcmd of cmd.commands) {\n if (!subcmd.hidden) {\n result.push(subcmd);\n result.push(...collectAllCommands(subcmd));\n }\n }\n }\n\n return result;\n}\n\n/**\n * Extracts all argument names from a command's schema.\n */\nfunction extractArguments(cmd: AnyPadroneCommand): { name: string; alias?: string; isBoolean: boolean }[] {\n const argList: { name: string; alias?: string; isBoolean: boolean }[] = [];\n\n if (!cmd.argsSchema) return argList;\n\n try {\n const argsMeta = cmd.meta?.fields;\n const { aliases } = extractSchemaMetadata(cmd.argsSchema, argsMeta, cmd.meta?.autoAlias);\n\n // Reverse aliases map (alias -> arg name)\n const aliasToArgument: Record<string, string> = {};\n for (const [arg, alias] of Object.entries(aliases)) {\n aliasToArgument[alias] = arg;\n }\n\n const jsonSchema = cmd.argsSchema['~standard'].jsonSchema.input({ target: 'draft-2020-12' }) as Record<string, any>;\n\n if (jsonSchema.type === 'object' && jsonSchema.properties) {\n for (const [key, prop] of Object.entries(jsonSchema.properties as Record<string, any>)) {\n const alias = Object.entries(aliases).find(([arg]) => arg === key)?.[1];\n argList.push({\n name: key,\n alias: alias,\n isBoolean: prop?.type === 'boolean',\n });\n }\n }\n } catch {\n // Ignore schema parsing errors\n }\n\n return argList;\n}\n\n/**\n * Generates a Bash completion script for the program.\n */\nexport function generateBashCompletion(program: AnyPadroneCommand): string {\n const programName = program.name;\n const commands = collectAllCommands(program);\n const commandNames = commands.map((c) => c.name).join(' ');\n\n // Collect all args from all commands\n const allArguments = new Set<string>();\n allArguments.add('--help');\n allArguments.add('--version');\n\n for (const cmd of [program, ...commands]) {\n for (const arg of extractArguments(cmd)) {\n allArguments.add(`--${arg.name}`);\n if (arg.alias) allArguments.add(`-${arg.alias}`);\n }\n }\n\n const argsList = Array.from(allArguments).join(' ');\n\n return `###-begin-${programName}-completion-###\n#\n# ${programName} command completion script\n#\n# Installation: ${programName} completion >> ~/.bashrc (or ~/.zshrc)\n# Or, maybe: ${programName} completion > /usr/local/etc/bash_completion.d/${programName}\n#\n\nif type complete &>/dev/null; then\n _${programName}_completion() {\n local cur prev words cword\n if type _get_comp_words_by_ref &>/dev/null; then\n _get_comp_words_by_ref -n = -n @ -n : -w words -i cword\n else\n cword=\"$COMP_CWORD\"\n words=(\"\\${COMP_WORDS[@]}\")\n fi\n\n cur=\"\\${words[cword]}\"\n prev=\"\\${words[cword-1]}\"\n\n local commands=\"${commandNames}\"\n local args=\"${argsList}\"\n\n # Complete args when current word starts with -\n if [[ \"$cur\" == -* ]]; then\n COMPREPLY=($(compgen -W \"$args\" -- \"$cur\"))\n return 0\n fi\n\n # Complete commands\n COMPREPLY=($(compgen -W \"$commands\" -- \"$cur\"))\n }\n complete -o bashdefault -o default -o nospace -F _${programName}_completion ${programName}\nelif type compdef &>/dev/null; then\n _${programName}_completion() {\n local si=$IFS\n local commands=\"${commandNames}\"\n local args=\"${argsList}\"\n\n if [[ \"\\${words[CURRENT]}\" == -* ]]; then\n compadd -- \\${=args}\n else\n compadd -- \\${=commands}\n fi\n IFS=$si\n }\n compdef _${programName}_completion ${programName}\nelif type compctl &>/dev/null; then\n _${programName}_completion() {\n local commands=\"${commandNames}\"\n local args=\"${argsList}\"\n\n if [[ \"\\${words[CURRENT]}\" == -* ]]; then\n reply=(\\${=args})\n else\n reply=(\\${=commands})\n fi\n }\n compctl -K _${programName}_completion ${programName}\nfi\n###-end-${programName}-completion-###`;\n}\n\n/**\n * Generates a Zsh completion script for the program.\n */\nexport function generateZshCompletion(program: AnyPadroneCommand): string {\n const programName = program.name;\n const commands = collectAllCommands(program);\n\n // Generate command completions with descriptions\n const commandCompletions = commands\n .map((cmd) => {\n const desc = cmd.description || cmd.title || '';\n const escapedDesc = desc.replace(/'/g, \"'\\\\''\").replace(/:/g, '\\\\:');\n return ` '${cmd.name}:${escapedDesc}'`;\n })\n .join('\\n');\n\n // Collect all args with descriptions\n const argumentCompletions: string[] = [];\n argumentCompletions.push(\" '--help[Show help information]'\");\n argumentCompletions.push(\" '--version[Show version number]'\");\n\n const seenArgs = new Set<string>(['help', 'version']);\n\n for (const cmd of [program, ...commands]) {\n for (const arg of extractArguments(cmd)) {\n if (seenArgs.has(arg.name)) continue;\n seenArgs.add(arg.name);\n\n const desc = cmd.meta?.fields?.[arg.name]?.description || '';\n const escapedDesc = desc.replace(/'/g, \"'\\\\''\").replace(/\\[/g, '\\\\[').replace(/\\]/g, '\\\\]');\n\n if (arg.alias) {\n argumentCompletions.push(` {-${arg.alias},--${arg.name}}'[${escapedDesc}]'`);\n } else {\n argumentCompletions.push(` '--${arg.name}[${escapedDesc}]'`);\n }\n }\n }\n\n return `#compdef ${programName}\n###-begin-${programName}-completion-###\n#\n# ${programName} command completion script for Zsh\n#\n# Installation: ${programName} completion >> ~/.zshrc\n# Or: ${programName} completion > ~/.zsh/completions/_${programName}\n#\n\n_${programName}() {\n local -a commands\n local -a args\n\n commands=(\n${commandCompletions}\n )\n\n args=(\n${argumentCompletions.join('\\n')}\n )\n\n _arguments -s \\\\\n $args \\\\\n '1: :->command' \\\\\n '*::arg:->args'\n\n case \"$state\" in\n command)\n _describe 'command' commands\n ;;\n esac\n}\n\n_${programName}\n###-end-${programName}-completion-###`;\n}\n\n/**\n * Generates a Fish completion script for the program.\n */\nexport function generateFishCompletion(program: AnyPadroneCommand): string {\n const programName = program.name;\n const commands = collectAllCommands(program);\n\n const lines: string[] = [\n `###-begin-${programName}-completion-###`,\n '#',\n `# ${programName} command completion script for Fish`,\n '#',\n `# Installation: ${programName} completion > ~/.config/fish/completions/${programName}.fish`,\n '#',\n '',\n `# Clear existing completions`,\n `complete -c ${programName} -e`,\n '',\n '# Commands',\n ];\n\n for (const cmd of commands) {\n const desc = cmd.description || cmd.title || '';\n const escapedDesc = desc.replace(/'/g, \"\\\\'\");\n lines.push(`complete -c ${programName} -n \"__fish_use_subcommand\" -a \"${cmd.name}\" -d '${escapedDesc}'`);\n }\n\n lines.push('');\n lines.push('# Global arguments');\n lines.push(`complete -c ${programName} -l help -d 'Show help information'`);\n lines.push(`complete -c ${programName} -l version -d 'Show version number'`);\n\n const seenArgs = new Set<string>(['help', 'version']);\n\n for (const cmd of [program, ...commands]) {\n for (const arg of extractArguments(cmd)) {\n if (seenArgs.has(arg.name)) continue;\n seenArgs.add(arg.name);\n\n const desc = cmd.meta?.fields?.[arg.name]?.description || '';\n const escapedDesc = desc.replace(/'/g, \"\\\\'\");\n\n if (arg.alias) {\n lines.push(`complete -c ${programName} -s ${arg.alias} -l ${arg.name} -d '${escapedDesc}'`);\n } else {\n lines.push(`complete -c ${programName} -l ${arg.name} -d '${escapedDesc}'`);\n }\n }\n }\n\n lines.push(`###-end-${programName}-completion-###`);\n\n return lines.join('\\n');\n}\n\n/**\n * Generates a PowerShell completion script for the program.\n */\nexport function generatePowerShellCompletion(program: AnyPadroneCommand): string {\n const programName = program.name;\n const commands = collectAllCommands(program);\n\n const commandNames = commands.map((c) => `'${c.name}'`).join(', ');\n\n return `###-begin-${programName}-completion-###\n#\n# ${programName} command completion script for PowerShell\n#\n# Installation: ${programName} completion >> $PROFILE\n#\n\nRegister-ArgumentCompleter -Native -CommandName ${programName} -ScriptBlock {\n param($wordToComplete, $commandAst, $cursorPosition)\n\n $commands = @(${commandNames})\n $args = @('--help', '--version')\n\n if ($wordToComplete -like '-*') {\n $args | Where-Object { $_ -like \"$wordToComplete*\" } | ForEach-Object {\n [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)\n }\n } else {\n $commands | Where-Object { $_ -like \"$wordToComplete*\" } | ForEach-Object {\n [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)\n }\n }\n}\n###-end-${programName}-completion-###`;\n}\n\n/**\n * Generates a completion script for the specified shell.\n */\nexport function generateCompletion(program: AnyPadroneCommand, shell: ShellType): string {\n switch (shell) {\n case 'bash':\n return generateBashCompletion(program);\n case 'zsh':\n return generateZshCompletion(program);\n case 'fish':\n return generateFishCompletion(program);\n case 'powershell':\n return generatePowerShellCompletion(program);\n default:\n throw new Error(`Unsupported shell: ${shell}`);\n }\n}\n\n/**\n * Gets the installation instructions for a shell completion script.\n */\nexport function getCompletionInstallInstructions(programName: string, shell: ShellType): string {\n switch (shell) {\n case 'bash':\n return `# Add to ~/.bashrc:\n${programName} completion bash >> ~/.bashrc\n\n# Or install system-wide:\n${programName} completion bash > /usr/local/etc/bash_completion.d/${programName}`;\n\n case 'zsh':\n return `# Add to ~/.zshrc:\n${programName} completion zsh >> ~/.zshrc\n\n# Or add to completions directory:\n${programName} completion zsh > ~/.zsh/completions/_${programName}`;\n\n case 'fish':\n return `# Install to Fish completions:\n${programName} completion fish > ~/.config/fish/completions/${programName}.fish`;\n\n case 'powershell':\n return `# Add to PowerShell profile:\n${programName} completion powershell >> $PROFILE`;\n\n default:\n return `# Run: ${programName} completion <shell>\n# Supported shells: bash, zsh, fish, powershell`;\n }\n}\n\n/**\n * Generates the completion output with automatic shell detection.\n * If shell is not specified, detects the current shell and provides instructions.\n */\nexport function generateCompletionOutput(program: AnyPadroneCommand, shell?: ShellType): string {\n const programName = program.name;\n\n if (shell) {\n return generateCompletion(program, shell);\n }\n\n // Auto-detect shell and provide instructions\n const detectedShell = detectShell();\n\n if (detectedShell) {\n const instructions = getCompletionInstallInstructions(programName, detectedShell);\n const script = generateCompletion(program, detectedShell);\n\n return `# Detected shell: ${detectedShell}\n#\n${instructions}\n#\n# Or evaluate directly (temporary, for current session only):\n# eval \"$(${programName} completion ${detectedShell})\"\n\n${script}`;\n }\n\n // Could not detect shell - provide usage info\n return `# Shell auto-detection failed.\n#\n# Usage: ${programName} completion <shell>\n#\n# Supported shells:\n# bash - Bash completion script\n# zsh - Zsh completion script\n# fish - Fish completion script\n# powershell - PowerShell completion script\n#\n# Example:\n# ${programName} completion bash >> ~/.bashrc\n# ${programName} completion zsh >> ~/.zshrc\n# ${programName} completion fish > ~/.config/fish/completions/${programName}.fish\n# ${programName} completion powershell >> $PROFILE`;\n}\n\nexport interface SetupCompletionsResult {\n /** The file that was written to. */\n file: string;\n /** Whether an existing completion block was replaced (true) or a new one was appended (false). */\n updated: boolean;\n}\n\n/**\n * Sets up shell completions by writing an eval snippet to the appropriate shell config file.\n * Uses marker comments for idempotency — re-running replaces the existing block.\n */\nexport function setupCompletions(programName: string, shell: ShellType): SetupCompletionsResult {\n const { existsSync, mkdirSync, writeFileSync } = require('node:fs') as typeof import('node:fs');\n const { join } = require('node:path') as typeof import('node:path');\n const { homedir } = require('node:os') as typeof import('node:os');\n\n const beginMarker = `###-begin-${programName}-completion-###`;\n const endMarker = `###-end-${programName}-completion-###`;\n const snippet = buildSetupSnippet(programName, shell, beginMarker, endMarker);\n\n if (shell === 'fish') {\n const completionsDir = join(homedir(), '.config', 'fish', 'completions');\n const filePath = join(completionsDir, `${programName}.fish`);\n mkdirSync(completionsDir, { recursive: true });\n const existed = existsSync(filePath);\n writeFileSync(filePath, `${snippet}\\n`);\n return { file: filePath, updated: existed };\n }\n\n const rcFile = getRcFile(shell);\n if (!rcFile) {\n throw new Error(`Could not determine config file for ${shell}.`);\n }\n\n return writeToRcFile(rcFile, snippet, beginMarker, endMarker);\n}\n\nfunction buildSetupSnippet(programName: string, shell: ShellType, beginMarker: string, endMarker: string): string {\n const evalCmd = `${programName} completion ${shell}`;\n\n switch (shell) {\n case 'bash':\n case 'zsh':\n return `${beginMarker}\\neval \"$(${evalCmd})\"\\n${endMarker}`;\n case 'fish':\n return `${beginMarker}\\n${evalCmd} | source\\n${endMarker}`;\n case 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Q,IAAI;AACvC,SAAO;GAAE,MAAM;GAAU,SAAS;GAAS;;CAG7C,MAAM,SAAS,UAAU,MAAM;AAC/B,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,uCAAuC,MAAM,GAAG;AAGlE,QAAO,cAAc,QAAQ,SAAS,aAAa,UAAU;;AAG/D,SAAS,kBAAkB,aAAqB,OAAkB,aAAqB,WAA2B;CAChH,MAAM,UAAU,GAAG,YAAY,cAAc;AAE7C,SAAQ,OAAR;EACE,KAAK;EACL,KAAK,MACH,QAAO,GAAG,YAAY,YAAY,QAAQ,MAAM;EAClD,KAAK,OACH,QAAO,GAAG,YAAY,IAAI,QAAQ,aAAa;EACjD,KAAK,aACH,QAAO,GAAG,YAAY,IAAI,QAAQ,wBAAwB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { r as HelpInfo } from "../formatter-XroimS3Q.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/docs/index.d.ts
|
|
4
|
+
type DocsFormat = 'markdown' | 'html' | 'man' | 'json';
|
|
5
|
+
type DocsOptions = {
|
|
6
|
+
/** Output format. Defaults to 'markdown'. */format?: DocsFormat; /** Output directory. If not set, docs are returned but not written. */
|
|
7
|
+
output?: string; /** Include hidden commands and options. Defaults to false. */
|
|
8
|
+
includeHidden?: boolean; /** Frontmatter generator for markdown files (VitePress, Starlight, etc.). */
|
|
9
|
+
frontmatter?: (info: HelpInfo, depth: number) => Record<string, unknown>; /** Whether to overwrite existing files. Defaults to true. */
|
|
10
|
+
overwrite?: boolean; /** Print what would be written without writing. */
|
|
11
|
+
dryRun?: boolean;
|
|
12
|
+
};
|
|
13
|
+
type DocsPage = {
|
|
14
|
+
/** File path relative to output directory (e.g., "deploy.md", "index.md"). */path: string; /** Generated content for this page. */
|
|
15
|
+
content: string; /** The command name this page documents. */
|
|
16
|
+
command: string;
|
|
17
|
+
};
|
|
18
|
+
type DocsResult = {
|
|
19
|
+
/** All generated pages. */pages: DocsPage[]; /** Files that were written (empty if no output dir). */
|
|
20
|
+
written: string[]; /** Files that were skipped (already exist, no overwrite). */
|
|
21
|
+
skipped: string[]; /** Files that failed to write. */
|
|
22
|
+
errors: {
|
|
23
|
+
file: string;
|
|
24
|
+
error: Error;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Generate documentation for a Padrone CLI program or command tree.
|
|
29
|
+
* Accepts either a PadroneProgram (from createPadrone()) or a raw AnyPadroneCommand.
|
|
30
|
+
*/
|
|
31
|
+
declare function generateDocs(program: object, options?: DocsOptions): DocsResult;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { DocsFormat, DocsOptions, DocsPage, DocsResult, generateDocs };
|
|
34
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/docs/index.ts"],"mappings":";;;KAWY,UAAA;AAAA,KAEA,WAAA;EAFA,6CAIV,MAAA,GAAS,UAAA;EAET,MAAA,WANoB;EAQpB,aAAA,YANqB;EAQrB,WAAA,IAAe,IAAA,EAAM,QAAA,EAAU,KAAA,aAAkB,MAAA,mBANxC;EAQT,SAAA,YAFiD;EAIjD,MAAA;AAAA;AAAA,KAGU,QAAA;EAbD,8EAeT,IAAA,UAXA;EAaA,OAAA,UAXqB;EAarB,OAAA;AAAA;AAAA,KAGU,UAAA;EAdV,2BAgBA,KAAA,EAAO,QAAA,IAdD;EAgBN,OAAA,YAbU;EAeV,OAAA;EAEA,MAAA;IAAU,IAAA;IAAc,KAAA,EAAO,KAAA;EAAA;AAAA;;AARjC;;;iBA2egB,YAAA,CAAa,OAAA,UAAiB,OAAA,GAAS,WAAA,GAAmB,UAAA"}
|