-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathschema.ts
More file actions
97 lines (78 loc) · 2.57 KB
/
schema.ts
File metadata and controls
97 lines (78 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2025, Salesforce, Inc.
* SPDX-License-Identifier: Apache-2
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
*/
import {Args, Flags} from '@oclif/core';
import {BaseCommand} from '@salesforce/b2c-tooling-sdk/cli';
import {readSchemaByQuery, listSchemas, type SchemaEntry} from '@salesforce/b2c-tooling-sdk/operations/docs';
import {t} from '../../i18n/index.js';
interface SchemaResult {
entry: SchemaEntry;
content: string;
}
interface ListResult {
entries: SchemaEntry[];
}
export default class DocsSchema extends BaseCommand<typeof DocsSchema> {
static args = {
query: Args.string({
description: 'Schema name or partial match (e.g., "catalog", "order")',
required: false,
}),
};
static description = t('commands.docs.schema.description', 'Read an XSD schema file');
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> catalog',
'<%= config.bin %> <%= command.id %> order',
'<%= config.bin %> <%= command.id %> --list',
'<%= config.bin %> <%= command.id %> catalog --json',
];
static flags = {
...BaseCommand.baseFlags,
list: Flags.boolean({
char: 'l',
description: 'List all available schemas',
default: false,
}),
};
protected operations = {
listSchemas,
readSchemaByQuery,
};
async run(): Promise<ListResult | SchemaResult> {
const {query} = this.args;
const {list} = this.flags;
// List mode
if (list) {
const entries = this.operations.listSchemas();
if (this.jsonEnabled()) {
return {entries};
}
this.log(t('commands.docs.schema.available', 'Available schemas:'));
for (const entry of entries) {
this.log(` ${entry.id}`);
}
this.log('');
this.log(t('commands.docs.schema.count', '{{count}} schemas available', {count: entries.length}));
return {entries};
}
// Read mode requires query
if (!query) {
this.error(t('commands.docs.schema.queryRequired', 'Schema name is required. Use --list to see all schemas.'));
}
const result = this.operations.readSchemaByQuery(query);
if (!result) {
this.error(t('commands.docs.schema.notFound', 'No schema found matching: {{query}}', {query}), {
suggestions: ['Try a broader search term', 'Use "b2c docs schema --list" to see available schemas'],
});
}
if (this.jsonEnabled()) {
return result;
}
// Output the schema content
process.stdout.write(result.content);
return result;
}
}