Skip to content

Commit ba2634a

Browse files
authored
Merge pull request #12606 from quarto-dev/feature/cliffy-info
dev-call cli-info - new command to produce JSON information of CLI options
2 parents fbc59a3 + dd7fd94 commit ba2634a

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

package/src/common/prepare-dist.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Configuration } from "../common/config.ts";
1212
import { buildFilter } from "./package-filters.ts";
1313
import { bundle } from "../util/deno.ts";
1414
import { info } from "../../../src/deno_ral/log.ts";
15-
import { buildAssets } from "../../../src/command/build-js/cmd.ts";
15+
import { buildAssets } from "../../../src/command/dev-call/build-artifacts/cmd.ts";
1616
import { initTreeSitter } from "../../../src/core/schema/deno-init-tree-sitter.ts";
1717
import {
1818
Dependency,

src/command/command.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { typstCommand } from "./typst/cmd.ts";
1818
import { capabilitiesCommand } from "./capabilities/cmd.ts";
1919
import { checkCommand } from "./check/cmd.ts";
2020
import { inspectCommand } from "./inspect/cmd.ts";
21-
import { buildJsCommand } from "./build-js/cmd.ts";
2221
import { installCommand } from "./install/cmd.ts";
2322
import { updateCommand } from "./update/cmd.ts";
2423
import { publishCommand } from "./publish/cmd.ts";
@@ -30,6 +29,7 @@ import { uninstallCommand } from "./uninstall/cmd.ts";
3029
import { createCommand } from "./create/cmd.ts";
3130
import { editorSupportCommand } from "./editor-support/cmd.ts";
3231
import { callCommand } from "./call/cmd.ts";
32+
import { devCallCommand } from "./dev-call/cmd.ts";
3333

3434
// deno-lint-ignore no-explicit-any
3535
export function commands(): Command<any>[] {
@@ -56,8 +56,8 @@ export function commands(): Command<any>[] {
5656
capabilitiesCommand,
5757
inspectCommand,
5858
checkCommand,
59-
buildJsCommand,
6059
editorSupportCommand,
6160
callCommand,
61+
devCallCommand,
6262
];
6363
}

src/command/build-js/cmd.ts renamed to src/command/dev-call/build-artifacts/cmd.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import {
1010
ESBuildAnalysis,
1111
esbuildAnalyze,
1212
esbuildCompile,
13-
} from "../../core/esbuild.ts";
14-
import { buildIntelligenceResources } from "../../core/schema/build-schema-file.ts";
15-
import { formatResourcePath, resourcePath } from "../../core/resources.ts";
13+
} from "../../../core/esbuild.ts";
14+
import { buildIntelligenceResources } from "../../../core/schema/build-schema-file.ts";
15+
import { formatResourcePath, resourcePath } from "../../../core/resources.ts";
1616
import { simple } from "acorn/walk";
1717
import { Parser } from "acorn/acorn";
1818
import classFields from "acorn-class-fields";
19-
import { initYamlIntelligenceResourcesFromFilesystem } from "../../core/schema/utils.ts";
19+
import { initYamlIntelligenceResourcesFromFilesystem } from "../../../core/schema/utils.ts";
2020

2121
// initialize language handlers
22-
import "../../core/handlers/handlers.ts";
23-
import { join } from "../../deno_ral/path.ts";
22+
import "../../../core/handlers/handlers.ts";
23+
import { join } from "../../../deno_ral/path.ts";
2424

2525
function ensureAllowableIDESyntax(src: string, filename: string) {
2626
const ast = Parser.extend(classFields).parse(src, {

src/command/dev-call/cmd.ts

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

0 commit comments

Comments
 (0)