add and test style from file

This commit is contained in:
bel
2020-03-15 16:55:46 +00:00
parent a544dcdde7
commit 061292386c
4 changed files with 52 additions and 8 deletions

View File

@@ -48,11 +48,11 @@ func NewFromFile(config string) (*Scheduler, error) {
if len(line) == 0 {
continue
}
schedule, command := splitScheduleCommand(line)
schedule, command, title := splitScheduleCommandTitle(line)
if len(schedule) == 0 || len(command) == 0 {
continue
}
job, err := NewJob(Bash, schedule, command)
job, err := newBashJob(schedule, command, title)
if err != nil {
logger.New().Error(err, "cannot fully parse file: new job error", config, ", sched", schedule, ", comm", command)
continue
@@ -80,16 +80,20 @@ func cleanLine(b []byte) []byte {
return b
}
func splitScheduleCommand(b []byte) (string, string) {
func splitScheduleCommandTitle(b []byte) (string, string, string) {
re := regexp.MustCompile(`^((\d+|\*\/\d+|(\d,)*\d+|\*) [ ]*){5,6}`)
schedule := string(re.Find(b))
if len(schedule) == 0 {
return "", ""
return "", "", ""
}
command := strings.TrimPrefix(string(b), schedule)
commandTitle := strings.TrimPrefix(string(b), schedule)
schedule = strings.TrimSpace(schedule)
command = strings.TrimSpace(command)
return schedule, command
commandTitle = strings.TrimSpace(commandTitle)
title := ""
if i := strings.LastIndex(commandTitle, "#"); i >= 0 {
title = commandTitle[i+1:]
}
return schedule, commandTitle, title
}
func (s *Scheduler) Start() error {