- Support df command

- Return warnings array from ParseSyntaxFiles() in addition to potential
  error. Not being able to parse the dir is a fatal error but if a
random file cannot be read, it should be considered a warning.
This commit is contained in:
Jesse Portnoy
2023-07-18 18:46:01 +01:00
parent 57b5bfb135
commit 449702f27b
4 changed files with 48 additions and 12 deletions
+12 -11
View File
@@ -62,27 +62,28 @@ func NewHighlighter(def *Def) *Highlighter {
// color's group (represented as one byte)
type LineMatch map[int]Group
func ParseSyntaxFiles(dir string, defs *[]*Def) error {
func ParseSyntaxFiles(dir string, defs *[]*Def) (error, []string){
pattern := "*.yaml"
files, err := filepath.Glob(dir + "/" + pattern)
var warnings []string
if err != nil {
return err
return err, nil
}
for _, file_path := range files {
file, err := ioutil.ReadFile(file_path)
if err != nil {
return err
warnings = append(warnings,err.Error())
}else {
d, err := ParseDef(file)
if err != nil {
warnings = append(warnings,err.Error())
}else{
*defs = append(*defs, d)
}
}
d, err := ParseDef(file)
if err != nil {
return err
continue
}
*defs = append(*defs, d)
}
return nil
return err, warnings
}
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int {