@libtmux/workspace-cli 0.1.0-alpha.11

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.
@@ -0,0 +1,90 @@
1
+ import {
2
+ createParser
3
+ } from "./main-bfnr2nkj.js";
4
+ import"./main-1de529jm.js";
5
+
6
+ // src/reference.ts
7
+ function commandCatalog(parser = createParser({ stdout: () => {}, stderr: () => {} })) {
8
+ const commands = [];
9
+ function visit(command, path) {
10
+ const help = command.createHelp();
11
+ const children = help.visibleCommands(command);
12
+ commands.push({
13
+ path,
14
+ description: command.description(),
15
+ arguments: command.registeredArguments.map((argument) => ({
16
+ name: argument.name(),
17
+ required: argument.required,
18
+ variadic: argument.variadic,
19
+ description: argument.description,
20
+ choices: argument.argChoices ?? [],
21
+ completion: parser.completionHints.get(argument)
22
+ })),
23
+ options: help.visibleOptions(command).map((option) => ({
24
+ flags: option.flags,
25
+ short: option.short,
26
+ long: option.long,
27
+ description: option.description,
28
+ value: option.required ? "required" : option.optional ? "optional" : "none",
29
+ variadic: Boolean(option.variadic),
30
+ choices: option.argChoices ?? [],
31
+ default: option.defaultValue,
32
+ completion: parser.completionHints.get(option)
33
+ })),
34
+ subcommands: children.map((child) => child.name())
35
+ });
36
+ for (const child of children)
37
+ visit(child, [...path, child.name()]);
38
+ }
39
+ visit(parser.command, []);
40
+ return { program: parser.command.name(), commands };
41
+ }
42
+ function code(value) {
43
+ const fence = "`".repeat(Math.max(0, ...[...value.matchAll(/`+/g)].map(([run]) => run.length)) + 1);
44
+ return `${fence} ${value} ${fence}`;
45
+ }
46
+ function commandMarkdown(catalog) {
47
+ const lines = [
48
+ "# Workspace command reference",
49
+ "",
50
+ "Commands and options come from the native parser. See the [CLI README](../README.md)",
51
+ "for operation behavior, output, and development status.",
52
+ "",
53
+ "Root options precede the subcommand. Each command lists its own accepted options.",
54
+ ""
55
+ ];
56
+ for (const command of catalog.commands) {
57
+ const name = [catalog.program, ...command.path].join(" ");
58
+ const arguments_ = command.arguments.map((argument) => {
59
+ const value = argument.name + (argument.variadic ? "..." : "");
60
+ return argument.required ? `<${value}>` : `[${value}]`;
61
+ });
62
+ const usage = [
63
+ name,
64
+ ...command.options.length ? ["[options]"] : [],
65
+ ...arguments_,
66
+ ...command.subcommands.length ? ["[command]"] : []
67
+ ].join(" ");
68
+ lines.push(`## ${name}`, "", command.description, "", `Usage: ${code(usage)}`, "");
69
+ if (command.subcommands.length)
70
+ lines.push(`Commands: ${command.subcommands.map(code).join(", ")}.`, "");
71
+ for (const argument of command.arguments) {
72
+ const choices = argument.choices.length ? ` Choices: ${argument.choices.map(code).join(", ")}.` : "";
73
+ lines.push(`- ${code(argument.name)}${argument.description ? `: ${argument.description}` : ""}${choices}`);
74
+ }
75
+ if (command.arguments.length)
76
+ lines.push("");
77
+ for (const option of command.options) {
78
+ const choices = option.choices.length ? ` Choices: ${option.choices.map(code).join(", ")}.` : "";
79
+ const fallback = option.default === undefined ? "" : ` Default: ${code(JSON.stringify(option.default))}.`;
80
+ lines.push(`- ${code(option.flags)}: ${option.description}${choices}${fallback}`);
81
+ }
82
+ lines.push("");
83
+ }
84
+ return lines.join(`
85
+ `);
86
+ }
87
+ export {
88
+ commandCatalog,
89
+ commandMarkdown
90
+ };