@@ -9,54 +9,57 @@ import (
9
9
"github.com/spf13/cobra"
10
10
)
11
11
12
- var checkCmd = & cobra.Command {
13
- Use : "check" ,
14
- Short : "check a numscript file" ,
15
- Args : cobra .ExactArgs (1 ),
16
- Run : func (cmd * cobra.Command , args []string ) {
17
- path := args [0 ]
18
-
19
- dat , err := os .ReadFile (path )
20
- if err != nil {
21
- os .Stderr .Write ([]byte (err .Error ()))
22
- return
23
- }
12
+ func check (path string ) {
13
+ dat , err := os .ReadFile (path )
14
+ if err != nil {
15
+ os .Stderr .Write ([]byte (err .Error ()))
16
+ return
17
+ }
24
18
25
- res := analysis .CheckSource (string (dat ))
26
- sort .Slice (res .Diagnostics , func (i , j int ) bool {
27
- p1 := res .Diagnostics [i ].Range .Start
28
- p2 := res .Diagnostics [j ].Range .Start
19
+ res := analysis .CheckSource (string (dat ))
20
+ sort .Slice (res .Diagnostics , func (i , j int ) bool {
21
+ p1 := res .Diagnostics [i ].Range .Start
22
+ p2 := res .Diagnostics [j ].Range .Start
29
23
30
- return p2 .GtEq (p1 )
31
- })
32
-
33
- for i , d := range res .Diagnostics {
34
- if i != 0 {
35
- fmt .Print ("\n \n " )
36
- }
37
- errType := analysis .SeverityToAnsiString (d .Kind .Severity ())
38
- fmt .Printf ("%s:%d:%d - %s\n %s\n " , path , d .Range .Start .Line , d .Range .Start .Character , errType , d .Kind .Message ())
39
- }
24
+ return p2 .GtEq (p1 )
25
+ })
40
26
41
- if len (res .Diagnostics ) != 0 {
42
- fmt .Printf ("\n \n " )
27
+ for i , d := range res .Diagnostics {
28
+ if i != 0 {
29
+ fmt .Print ("\n \n " )
43
30
}
31
+ errType := analysis .SeverityToAnsiString (d .Kind .Severity ())
32
+ fmt .Printf ("%s:%d:%d - %s\n %s\n " , path , d .Range .Start .Line , d .Range .Start .Character , errType , d .Kind .Message ())
33
+ }
44
34
45
- errorsCount := res .GetErrorsCount ()
46
- if errorsCount != 0 {
35
+ if len (res .Diagnostics ) != 0 {
36
+ fmt .Printf ("\n \n " )
37
+ }
47
38
48
- var pluralizedError string
49
- if errorsCount == 1 {
50
- pluralizedError = "error"
51
- } else {
52
- pluralizedError = "errors"
39
+ errorsCount := res .GetErrorsCount ()
40
+ if errorsCount != 0 {
53
41
54
- }
42
+ var pluralizedError string
43
+ if errorsCount == 1 {
44
+ pluralizedError = "error"
45
+ } else {
46
+ pluralizedError = "errors"
55
47
56
- fmt .Printf ("\033 [31mFound %d %s\033 [0m\n " , errorsCount , pluralizedError )
57
- os .Exit (1 )
58
48
}
59
49
60
- fmt .Printf ("No errors found ✅\n " )
50
+ fmt .Printf ("\033 [31mFound %d %s\033 [0m\n " , errorsCount , pluralizedError )
51
+ os .Exit (1 )
52
+ }
53
+
54
+ fmt .Printf ("No errors found ✅\n " )
55
+ }
56
+
57
+ var checkCmd = & cobra.Command {
58
+ Use : "check" ,
59
+ Short : "check a numscript file" ,
60
+ Args : cobra .ExactArgs (1 ),
61
+ Run : func (cmd * cobra.Command , args []string ) {
62
+ path := args [0 ]
63
+ check (path )
61
64
},
62
65
}
0 commit comments