()
| 173 | } |
| 174 | |
| 175 | func getValidateCommand() cli.Command { |
| 176 | return cli.Command{ |
| 177 | Name: "validate", |
| 178 | ShortName: "v", |
| 179 | Usage: "Validate document", |
| 180 | Description: ` |
| 181 | Validate document against schema. |
| 182 | It'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 | |
| 211 | func getInitDbCommand() cli.Command { |
| 212 | return cli.Command{ |
no test coverage detected