@osovv/grace-cli 3.5.0 → 3.7.0

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,126 @@
1
+ import { defineCommand } from "citty";
2
+
3
+ import { findModules, loadGraceArtifactIndex, resolveModule } from "./query/core";
4
+ import { formatModuleFindTable, formatModuleText } from "./query/render";
5
+
6
+ function resolveFormat(format: unknown, json: unknown, allowed: string[], defaultFormat: string) {
7
+ const resolved = Boolean(json) ? "json" : String(format ?? defaultFormat);
8
+ if (!allowed.includes(resolved)) {
9
+ throw new Error(`Unsupported format \`${resolved}\`. Use ${allowed.map((value) => `\`${value}\``).join(" or ")}.`);
10
+ }
11
+
12
+ return resolved;
13
+ }
14
+
15
+ export const moduleCommand = defineCommand({
16
+ meta: {
17
+ name: "module",
18
+ description: "Query shared GRACE module artifacts.",
19
+ },
20
+ subCommands: {
21
+ find: defineCommand({
22
+ meta: {
23
+ name: "find",
24
+ description: "Find GRACE modules by id, name, path, purpose, annotations, verification, or dependencies.",
25
+ },
26
+ args: {
27
+ query: {
28
+ type: "positional",
29
+ required: false,
30
+ description: "Search query or path",
31
+ },
32
+ path: {
33
+ type: "string",
34
+ alias: "p",
35
+ description: "Project root to inspect",
36
+ default: ".",
37
+ },
38
+ type: {
39
+ type: "string",
40
+ description: "Filter by module type",
41
+ },
42
+ dependsOn: {
43
+ type: "string",
44
+ description: "Filter by dependency id",
45
+ },
46
+ format: {
47
+ type: "string",
48
+ alias: "f",
49
+ description: "Output format: table or json",
50
+ default: "table",
51
+ },
52
+ json: {
53
+ type: "boolean",
54
+ description: "Shortcut for --format json",
55
+ default: false,
56
+ },
57
+ },
58
+ async run(context) {
59
+ const format = resolveFormat(context.args.format, context.args.json, ["table", "json"], "table");
60
+ const index = loadGraceArtifactIndex(String(context.args.path ?? "."));
61
+ const matches = findModules(index, {
62
+ query: context.args.query ? String(context.args.query) : undefined,
63
+ type: context.args.type ? String(context.args.type) : undefined,
64
+ dependsOn: context.args.dependsOn ? String(context.args.dependsOn) : undefined,
65
+ });
66
+
67
+ if (format === "json") {
68
+ process.stdout.write(`${JSON.stringify(matches, null, 2)}\n`);
69
+ return;
70
+ }
71
+
72
+ process.stdout.write(`${formatModuleFindTable(matches)}\n`);
73
+ },
74
+ }),
75
+ show: defineCommand({
76
+ meta: {
77
+ name: "show",
78
+ description: "Show the shared/public GRACE record for a module id or path.",
79
+ },
80
+ args: {
81
+ target: {
82
+ type: "positional",
83
+ description: "Module id or file/path target",
84
+ },
85
+ path: {
86
+ type: "string",
87
+ alias: "p",
88
+ description: "Project root to inspect",
89
+ default: ".",
90
+ },
91
+ with: {
92
+ type: "string",
93
+ description: "Optional extras, currently supports: verification",
94
+ default: "",
95
+ },
96
+ format: {
97
+ type: "string",
98
+ alias: "f",
99
+ description: "Output format: text or json",
100
+ default: "text",
101
+ },
102
+ json: {
103
+ type: "boolean",
104
+ description: "Shortcut for --format json",
105
+ default: false,
106
+ },
107
+ },
108
+ async run(context) {
109
+ const format = resolveFormat(context.args.format, context.args.json, ["text", "json"], "text");
110
+ const index = loadGraceArtifactIndex(String(context.args.path ?? "."));
111
+ const moduleRecord = resolveModule(index, String(context.args.target));
112
+ const includeVerification = String(context.args.with ?? "")
113
+ .split(",")
114
+ .map((value) => value.trim().toLowerCase())
115
+ .includes("verification");
116
+
117
+ if (format === "json") {
118
+ process.stdout.write(`${JSON.stringify(moduleRecord, null, 2)}\n`);
119
+ return;
120
+ }
121
+
122
+ process.stdout.write(`${formatModuleText(moduleRecord, { withVerification: includeVerification })}\n`);
123
+ },
124
+ }),
125
+ },
126
+ });
package/src/grace.ts CHANGED
@@ -2,16 +2,20 @@
2
2
 
3
3
  import { defineCommand, type CommandDef, runMain } from "citty";
4
4
 
5
+ import { fileCommand } from "./grace-file";
5
6
  import { lintCommand } from "./grace-lint";
7
+ import { moduleCommand } from "./grace-module";
6
8
 
7
9
  const main = defineCommand({
8
10
  meta: {
9
11
  name: "grace",
10
- version: "3.5.0",
11
- description: "GRACE CLI for linting semantic markup and GRACE project artifacts.",
12
+ version: "3.7.0",
13
+ description: "GRACE CLI for linting semantic markup and querying GRACE project artifacts.",
12
14
  },
13
15
  subCommands: {
16
+ file: fileCommand,
14
17
  lint: lintCommand,
18
+ module: moduleCommand,
15
19
  },
16
20
  });
17
21