File tree Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { getDefaultSchemaLocation , loadDocument } from '../cli-util' ;
2
+
3
+ type Options = {
4
+ schema : string ;
5
+ } ;
6
+
7
+ /**
8
+ * CLI action for checking schema
9
+ */
10
+ export async function check ( _projectPath : string , options : Options ) {
11
+ const schema = options . schema ?? getDefaultSchemaLocation ( ) ;
12
+ await loadDocument ( schema ) ;
13
+ console . log ( 'The schema is valid.' ) ;
14
+ }
Original file line number Diff line number Diff line change
1
+ export * from './check' ;
2
+ export * from './format' ;
1
3
export * from './generate' ;
2
4
export * from './info' ;
3
5
export * from './init' ;
4
6
export * from './repl' ;
5
- export * from './format' ;
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ const CHECK_VERSION_TIMEOUT = 1000;
27
27
* @param services Language services
28
28
* @returns Parsed and validated AST
29
29
*/
30
- export async function loadDocument ( fileName : string ) : Promise < Model > {
30
+ export async function loadDocument ( fileName : string , validateOnly = false ) : Promise < Model > {
31
31
const services = createZModelServices ( NodeFileSystem ) . ZModel ;
32
32
const extensions = services . LanguageMetaData . fileExtensions ;
33
33
if ( ! extensions . includes ( path . extname ( fileName ) ) ) {
@@ -93,6 +93,10 @@ export async function loadDocument(fileName: string): Promise<Model> {
93
93
94
94
const model = document . parseResult . value as Model ;
95
95
96
+ if ( validateOnly ) {
97
+ return model ;
98
+ }
99
+
96
100
// merge all declarations into the main document
97
101
const imported = mergeImportsDeclarations ( langiumDocuments , model ) ;
98
102
Original file line number Diff line number Diff line change @@ -60,6 +60,16 @@ export const formatAction = async (options: Parameters<typeof actions.format>[1]
60
60
) ;
61
61
} ;
62
62
63
+ export const checkAction = async ( options : Parameters < typeof actions . check > [ 1 ] ) : Promise < void > => {
64
+ await telemetry . trackSpan (
65
+ 'cli:command:start' ,
66
+ 'cli:command:complete' ,
67
+ 'cli:command:error' ,
68
+ { command : 'check' } ,
69
+ ( ) => actions . check ( process . cwd ( ) , options )
70
+ ) ;
71
+ } ;
72
+
63
73
export function createProgram ( ) {
64
74
const program = new Command ( 'zenstack' ) ;
65
75
@@ -131,6 +141,12 @@ export function createProgram() {
131
141
. option ( '--no-prisma-style' , 'do not use prisma style' )
132
142
. action ( formatAction ) ;
133
143
144
+ program
145
+ . command ( 'check' )
146
+ . description ( 'Check a ZenStack schema file for syntax or semantic errors.' )
147
+ . addOption ( schemaOption )
148
+ . action ( checkAction ) ;
149
+
134
150
// make sure config is loaded before actions run
135
151
program . hook ( 'preAction' , async ( _ , actionCommand ) => {
136
152
let configFile : string | undefined = actionCommand . opts ( ) . config ;
You can’t perform that action at this time.
0 commit comments