Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Jul 26, 2024
1 parent f34927f commit e493f63
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,57 @@ import (
"github.com/spf13/cobra"
)

var checkCmd = &cobra.Command{
Use: "check",
Short: "check a numscript file",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
path := args[0]

dat, err := os.ReadFile(path)
if err != nil {
os.Stderr.Write([]byte(err.Error()))
return
}
func check(path string) {
dat, err := os.ReadFile(path)
if err != nil {
os.Stderr.Write([]byte(err.Error()))
return
}

res := analysis.CheckSource(string(dat))
sort.Slice(res.Diagnostics, func(i, j int) bool {
p1 := res.Diagnostics[i].Range.Start
p2 := res.Diagnostics[j].Range.Start
res := analysis.CheckSource(string(dat))
sort.Slice(res.Diagnostics, func(i, j int) bool {
p1 := res.Diagnostics[i].Range.Start
p2 := res.Diagnostics[j].Range.Start

return p2.GtEq(p1)
})

for i, d := range res.Diagnostics {
if i != 0 {
fmt.Print("\n\n")
}
errType := analysis.SeverityToAnsiString(d.Kind.Severity())
fmt.Printf("%s:%d:%d - %s\n%s\n", path, d.Range.Start.Line, d.Range.Start.Character, errType, d.Kind.Message())
}
return p2.GtEq(p1)
})

if len(res.Diagnostics) != 0 {
fmt.Printf("\n\n")
for i, d := range res.Diagnostics {
if i != 0 {
fmt.Print("\n\n")
}
errType := analysis.SeverityToAnsiString(d.Kind.Severity())
fmt.Printf("%s:%d:%d - %s\n%s\n", path, d.Range.Start.Line, d.Range.Start.Character, errType, d.Kind.Message())
}

errorsCount := res.GetErrorsCount()
if errorsCount != 0 {
if len(res.Diagnostics) != 0 {
fmt.Printf("\n\n")
}

var pluralizedError string
if errorsCount == 1 {
pluralizedError = "error"
} else {
pluralizedError = "errors"
errorsCount := res.GetErrorsCount()
if errorsCount != 0 {

}
var pluralizedError string
if errorsCount == 1 {
pluralizedError = "error"
} else {
pluralizedError = "errors"

fmt.Printf("\033[31mFound %d %s\033[0m\n", errorsCount, pluralizedError)
os.Exit(1)
}

fmt.Printf("No errors found ✅\n")
fmt.Printf("\033[31mFound %d %s\033[0m\n", errorsCount, pluralizedError)
os.Exit(1)
}

fmt.Printf("No errors found ✅\n")
}

var checkCmd = &cobra.Command{
Use: "check",
Short: "check a numscript file",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
path := args[0]
check(path)
},
}

0 comments on commit e493f63

Please sign in to comment.