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

Method Parse

lib/crontab.go:104–259  ·  view source on GitHub ↗
(noAutoDiscover bool)

Source from the content-addressed store, hash-verified

102}
103
104func (c *Crontab) Parse(noAutoDiscover bool) (error, int) {
105 lines, errCode, err := c.load()
106 if err != nil {
107 return err, errCode
108 }
109
110 if len(c.Lines) > 0 {
111 panic("Cannot read into non-empty crontab struct")
112 }
113
114 var autoDiscoverLine *Line
115 var name string
116 var ignored bool
117
118 for lineIndex, fullLine := range lines {
119 lineNumber := lineIndex + 1 // Convert to 1-indexed
120 var cronExpression string
121 var command []string
122 var runAs string
123
124 fullLine = strings.TrimSpace(fullLine)
125 isComment := false
126
127 // Check for special Name: comment, handle other comments normally
128 if nameMatch := regexp.MustCompile(`^#\s*Name:\s*(.+)$`).FindStringSubmatch(fullLine); nameMatch != nil {
129 name = strings.TrimSpace(nameMatch[1])
130 continue
131 }
132
133 // Check for special cronitor: ignore comment
134 if ignoreMatch := regexp.MustCompile(`^#\s*cronitor:\s*ignore\s*$`).FindStringSubmatch(fullLine); ignoreMatch != nil {
135 ignored = true
136 continue
137 }
138
139 // If the line is a comment, check if it's a disabled job or just a regular comment
140 if strings.HasPrefix(fullLine, "#") {
141 commentContent := strings.TrimSpace(strings.TrimPrefix(fullLine, "#"))
142
143 // Only treat as a potential disabled job if it looks like a valid cron expression
144 if isValidCronExpression(commentContent) {
145 fullLine = commentContent
146 isComment = true
147 } else {
148 // This is just a regular comment, create a comment line and continue
149 line := Line{
150 IsComment: true,
151 IsJob: false,
152 Name: name,
153 FullLine: strings.TrimSpace(strings.TrimPrefix(fullLine, "#")),
154 LineNumber: lineNumber,
155 Ignored: ignored,
156 Crontab: c.lightweightCopy(),
157 }
158
159 // Reset the name and ignored for the next line
160 if name != "" {
161 name = ""

Callers 7

ReadCrontabsInDirectoryFunction · 0.80
ReadCrontabFromFileFunction · 0.80
processCrontabFunction · 0.80
handleGetCrontabsFunction · 0.80
handlePostCrontabsFunction · 0.80
handlePutCrontabsFunction · 0.80

Calls 7

loadMethod · 0.95
lightweightCopyMethod · 0.95
IsRootMethod · 0.95
IsAutoDiscoverCommandMethod · 0.95
isValidCronExpressionFunction · 0.85
isSixFieldCronExpressionFunction · 0.85
createAutoDiscoverLineFunction · 0.85

Tested by

no test coverage detected