Skip to content

Commit 61eba69

Browse files
committed
dev-call - new command to generate JSON information
1 parent a1915e4 commit 61eba69

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/command/command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { uninstallCommand } from "./uninstall/cmd.ts";
3030
import { createCommand } from "./create/cmd.ts";
3131
import { editorSupportCommand } from "./editor-support/cmd.ts";
3232
import { callCommand } from "./call/cmd.ts";
33+
import { devCallCommand } from "./dev-call/cmd.ts";
3334

3435
// deno-lint-ignore no-explicit-any
3536
export function commands(): Command<any>[] {
@@ -59,5 +60,6 @@ export function commands(): Command<any>[] {
5960
buildJsCommand,
6061
editorSupportCommand,
6162
callCommand,
63+
devCallCommand,
6264
];
6365
}

src/command/dev-call/cmd.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Command } from "cliffy/command/mod.ts";
2+
import { quartoConfig } from "../../core/quarto.ts";
3+
import { commands } from "../command.ts";
4+
5+
type CommandOptionInfo = {
6+
name: string;
7+
description: string;
8+
args: [];
9+
flags: string[];
10+
equalsSign: boolean;
11+
typeDefinition: string;
12+
};
13+
14+
type CommandInfo = {
15+
name: string;
16+
description: string;
17+
options: CommandOptionInfo[];
18+
// arguments: string[];
19+
// subcommands: CommandInfo[];
20+
// aliases: string[];
21+
examples: { name: string; description: string }[];
22+
// flags: string[];
23+
usage: string;
24+
commands: CommandInfo[];
25+
};
26+
27+
const generateCliInfoCommand = new Command()
28+
.name("cli-info")
29+
.description("Generate JSON information about the Quarto CLI.")
30+
.action(async () => {
31+
const output: Record<string, unknown> = {};
32+
output["version"] = quartoConfig.version();
33+
const commandsInfo: CommandInfo[] = [];
34+
output["commands"] = commandsInfo;
35+
// deno-lint-ignore no-explicit-any
36+
const cmdAsJson = (cmd: any): CommandInfo => {
37+
return {
38+
name: cmd.getName(),
39+
description: cmd.getDescription(),
40+
options: cmd.getOptions(),
41+
usage: cmd.getUsage(),
42+
examples: cmd.getExamples(),
43+
commands: cmd.getCommands().map(cmdAsJson),
44+
};
45+
};
46+
output["commands"] = commands().map(cmdAsJson);
47+
console.log(JSON.stringify(output, null, 2));
48+
});
49+
50+
export const devCallCommand = new Command()
51+
.name("dev-call")
52+
.description(
53+
"Access internals of Quarto - this command is not intended for general use.",
54+
)
55+
.action(() => {
56+
devCallCommand.showHelp();
57+
Deno.exit(1);
58+
}).command("cli-info", generateCliInfoCommand);

0 commit comments

Comments
 (0)