mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-05 08:27:19 -04:00
- 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:
+12
-11
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user