File tree 1 file changed +19
-4
lines changed
1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change 8
8
"io/ioutil"
9
9
"os"
10
10
"path"
11
+ "path/filepath"
11
12
12
13
ucl "github.com/cesanta/ucl"
13
14
validateJSONSchema "github.com/cesanta/validate-json/schema"
@@ -54,19 +55,21 @@ func (s *Schema) Validate(cfg *config.Config) error {
54
55
func New () (* Schema , error ) {
55
56
files := make (map [string ]string )
56
57
57
- if len (* commandLineSchemaPath ) == 0 {
58
- return nil , nil
58
+ schemaDir , err := getSchemaDir ()
59
+
60
+ if err != nil {
61
+ return nil , err
59
62
}
60
63
61
- if _files , err := ioutil .ReadDir (* commandLineSchemaPath ); err != nil {
64
+ if _files , err := ioutil .ReadDir (schemaDir ); err != nil {
62
65
if os .IsNotExist (err ) {
63
66
return nil , nil
64
67
}
65
68
66
69
return nil , err
67
70
} else {
68
71
for _ , _file := range _files {
69
- files [_file .Name ()] = path .Join (* commandLineSchemaPath , _file .Name ())
72
+ files [_file .Name ()] = path .Join (schemaDir , _file .Name ())
70
73
}
71
74
}
72
75
@@ -114,3 +117,15 @@ func readSchema(filePath string) (parsedFileContent ucl.Value, err error) {
114
117
115
118
return
116
119
}
120
+
121
+ func getSchemaDir () (string , error ) {
122
+ if len (* commandLineSchemaPath ) > 0 {
123
+ return filepath .Abs (* commandLineSchemaPath )
124
+ }
125
+
126
+ if dir , err := filepath .Abs (filepath .Dir (os .Args [0 ])); err != nil {
127
+ return "" , err
128
+ } else {
129
+ return path .Join (dir , "schema" ), nil
130
+ }
131
+ }
You can’t perform that action at this time.
0 commit comments