MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / createAutoDiscoverLine

Function createAutoDiscoverLine

lib/crontab.go:791–817  ·  view source on GitHub ↗
(crontab *Crontab)

Source from the content-addressed store, hash-verified

789}
790
791func createAutoDiscoverLine(crontab *Crontab) *Line {
792 cronExpression := fmt.Sprintf("%d * * * *", randomMinute())
793 if crontab.UsesSixFieldExpressions {
794 cronExpression = fmt.Sprintf("* %s", cronExpression)
795 }
796
797 // Normalize the command so it can be run reliably from crontab.
798 commandToRun := strings.Join(os.Args, " ")
799 commandToRun = strings.Replace(commandToRun, "--save", "", -1)
800 commandToRun = strings.Replace(commandToRun, "--verbose", "", -1)
801 commandToRun = strings.Replace(commandToRun, "-v", "", -1)
802 commandToRun = strings.Replace(commandToRun, "--interactive", "", -1)
803 commandToRun = strings.Replace(commandToRun, "-i", "", -1)
804 if len(crontab.Filename) > 0 {
805 commandToRun = strings.Replace(commandToRun, crontab.Filename, crontab.CanonicalName(), -1)
806 }
807
808 // Remove existing --auto flag before adding a new one to prevent doubling up
809 commandToRun = strings.Replace(commandToRun, "--auto", "", -1)
810 commandToRun = strings.Replace(commandToRun, " discover", " discover --auto ", -1)
811
812 line := Line{}
813 line.CronExpression = cronExpression
814 line.CommandToRun = commandToRun
815 line.FullLine = fmt.Sprintf("%s %s", line.CronExpression, line.CommandToRun)
816 return &line
817}
818
819func isSixFieldCronExpression(splitLine []string) bool {
820 matchDigitOrWildcard, _ := regexp.MatchString("^[-,?*/0-9]+$", splitLine[5])

Callers 1

ParseMethod · 0.85

Calls 2

randomMinuteFunction · 0.85
CanonicalNameMethod · 0.80

Tested by

no test coverage detected