Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/inspect/cmd.ts
3584 views
1
/*
2
* cmd.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { Command } from "cliffy/command/mod.ts";
8
9
import {
10
initState,
11
setInitializer,
12
} from "../../core/lib/yaml-validation/state.ts";
13
import { initYamlIntelligenceResourcesFromFilesystem } from "../../core/schema/utils.ts";
14
import { inspectConfig } from "../../inspect/inspect.ts";
15
16
export const inspectCommand = new Command()
17
.name("inspect")
18
.arguments("[path] [output]")
19
.description(
20
"Inspect a Quarto project or input path.\n\nInspecting a project returns its config and engines.\n" +
21
"Inspecting an input path return its formats, engine, and dependent resources.\n\n" +
22
"Emits results of inspection as JSON to output (or stdout if not provided).",
23
)
24
.hidden()
25
.example(
26
"Inspect project in current directory",
27
"quarto inspect",
28
)
29
.example(
30
"Inspect project in directory",
31
"quarto inspect myproject",
32
)
33
.example(
34
"Inspect input path",
35
"quarto inspect document.md",
36
)
37
.example(
38
"Inspect input path and write to file",
39
"quarto inspect document.md output.json",
40
)
41
.action(
42
async (
43
// deno-lint-ignore no-explicit-any
44
_options: any,
45
path?: string,
46
output?: string,
47
) => {
48
// one-time initialization of yaml validation modules
49
setInitializer(initYamlIntelligenceResourcesFromFilesystem);
50
await initState();
51
52
path = path || Deno.cwd();
53
54
// get the config
55
const config = await inspectConfig(path);
56
57
// write using the requisite format
58
const outputJson = JSON.stringify(config, undefined, 2);
59
60
if (!output) {
61
Deno.stdout.writeSync(
62
new TextEncoder().encode(outputJson + "\n"),
63
);
64
} else {
65
Deno.writeTextFileSync(output, outputJson + "\n");
66
}
67
},
68
);
69
70