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:
+4
-1
@@ -28,11 +28,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var defs []*highlight.Def
|
var defs []*highlight.Def
|
||||||
err := highlight.ParseSyntaxFiles(syn_dir, &defs)
|
err, warnings := highlight.ParseSyntaxFiles(syn_dir, &defs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// it's up to you what to do with the warnings. You can print them or ignore them
|
||||||
|
fmt.Println(warnings)
|
||||||
|
|
||||||
highlight.ResolveIncludes(defs)
|
highlight.ResolveIncludes(defs)
|
||||||
|
|
||||||
fileSrc, _ := ioutil.ReadFile(os.Args[1])
|
fileSrc, _ := ioutil.ReadFile(os.Args[1])
|
||||||
|
|||||||
+12
-11
@@ -62,27 +62,28 @@ func NewHighlighter(def *Def) *Highlighter {
|
|||||||
// color's group (represented as one byte)
|
// color's group (represented as one byte)
|
||||||
type LineMatch map[int]Group
|
type LineMatch map[int]Group
|
||||||
|
|
||||||
func ParseSyntaxFiles(dir string, defs *[]*Def) error {
|
func ParseSyntaxFiles(dir string, defs *[]*Def) (error, []string){
|
||||||
pattern := "*.yaml"
|
pattern := "*.yaml"
|
||||||
files, err := filepath.Glob(dir + "/" + pattern)
|
files, err := filepath.Glob(dir + "/" + pattern)
|
||||||
|
var warnings []string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file_path := range files {
|
for _, file_path := range files {
|
||||||
file, err := ioutil.ReadFile(file_path)
|
file, err := ioutil.ReadFile(file_path)
|
||||||
if err != nil {
|
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 {
|
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int {
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
filetype: ping
|
||||||
|
|
||||||
|
detect:
|
||||||
|
filename: "\\.df$"
|
||||||
|
header: "(^Filesystem[[:space:]]+)"
|
||||||
|
|
||||||
|
rules:
|
||||||
|
# header
|
||||||
|
- cyan: "(Filesystem|Size|1K-blocks|(I)?Use(d)?(%)?|Avail(able)?|Mounted on|IFree|Inodes)"
|
||||||
|
- blue: "(\\/[-\\w\\d.]+)+\\s"
|
||||||
|
# Ks
|
||||||
|
- green: "\\s\\d*[.,]?\\d(K|B)i?\\s|\b\\d{1,3}\b"
|
||||||
|
# Ms
|
||||||
|
- magenta: "\\s\\d*[.,]?\\dMi?\\s|\b\\d{4,6}\b"
|
||||||
|
# Gs
|
||||||
|
- cyan: "\\s\\d*[.,]?\\dGi?\\s|\b\\d{4,6}\b"
|
||||||
|
# Ts
|
||||||
|
- preproc: "\\s\\d*[.,]?\\dTi?\\s|\b\\d{4,6}\b"
|
||||||
|
# Mounted on
|
||||||
|
- green: "\\/$|(\\/[-\\w\\d. ]+)+$"
|
||||||
|
# Use% <= 60
|
||||||
|
- high.green: "\\s[1-6]?[0-9]%\\s"
|
||||||
|
# Use% <= 70 - 89
|
||||||
|
- yellow: "\\s[78][0-9]%\\s"
|
||||||
|
# Use 90-97%
|
||||||
|
- red: "\\s9[0-7]%\\s"
|
||||||
|
# Use 98-100%
|
||||||
|
- preproc: "\\s9[89]%|100%\\s"
|
||||||
|
- type: "(tmpfs|(u|/)?dev|(/)?run|shm|(/)?boot|nfs|/home|/var|/tmp|swap)"
|
||||||
|
- constant.number: "[[:space:]]+([0-9])+[[:space:]]+"
|
||||||
|
|
||||||
@@ -24,4 +24,5 @@ rules:
|
|||||||
- red: "DUP\\!"
|
- red: "DUP\\!"
|
||||||
- red: "(Destination Host Unreachable|100(\\.0)?% packet loss)"
|
- red: "(Destination Host Unreachable|100(\\.0)?% packet loss)"
|
||||||
- red: ".+unknown\\shost\\s(.+)"
|
- red: ".+unknown\\shost\\s(.+)"
|
||||||
|
- red: "Temporary failure in name resolution"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user