|
| 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