MCPcopy Create free account
hub / github.com/cloudwan/gohan / getValidateCommand

Function getValidateCommand

cli/cli.go:175–209  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

173}
174
175func getValidateCommand() cli.Command {
176 return cli.Command{
177 Name: "validate",
178 ShortName: "v",
179 Usage: "Validate document",
180 Description: `
181Validate document against schema.
182It's especially useful to validate schema files against gohan meta-schema.`,
183 Flags: []cli.Flag{
184 cli.StringFlag{Name: "schema, s", Value: "etc/schema/gohan.json", Usage: "Schema path"},
185 cli.StringSliceFlag{Name: "document, d", Usage: "Document path"},
186 },
187 Action: func(c *cli.Context) {
188 schemaPath := c.String("schema")
189 documentPaths := c.StringSlice("document")
190 if len(documentPaths) == 0 {
191 util.ExitFatalf("At least one document should be specified for validation\n")
192 }
193
194 manager := schema.GetManager()
195 err := manager.LoadSchemaFromFile(schemaPath)
196 if err != nil {
197 util.ExitFatal("Failed to parse schema:", err)
198 }
199
200 for _, documentPath := range documentPaths {
201 err = manager.LoadSchemaFromFile(documentPath)
202 if err != nil {
203 util.ExitFatalf("Schema is not valid, see errors below:\n%s\n", err)
204 }
205 }
206 fmt.Println("Schema is valid")
207 },
208 }
209}
210
211func getInitDbCommand() cli.Command {
212 return cli.Command{

Callers 1

RunFunction · 0.85

Calls 2

LoadSchemaFromFileMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected