From 04b5bac72790a3ddba6ff8b4af4a3cfef63682fb Mon Sep 17 00:00:00 2001 From: Motalleb Fallahnezhad Date: Fri, 28 Jun 2024 18:38:21 +0330 Subject: [PATCH] fix: lint issues --- cmd/parser/cron_string.go | 11 +++++---- cmd/parser/parser.go | 2 ++ test.yaml | 49 --------------------------------------- 3 files changed, 9 insertions(+), 53 deletions(-) delete mode 100644 test.yaml diff --git a/cmd/parser/cron_string.go b/cmd/parser/cron_string.go index d1d7a6f..7c78f16 100644 --- a/cmd/parser/cron_string.go +++ b/cmd/parser/cron_string.go @@ -26,6 +26,9 @@ func NewCronFromFile(filePath string) CronString { log.Panicf("can't open cron file: %v", err) } stat, err := file.Stat() + if err != nil { + log.Panicf("can't stat cron file: %v", err) + } content := make([]byte, stat.Size()) file.Read(content) return CronString{string(content)} @@ -70,13 +73,13 @@ func (s CronString) lines() []string { return strings.Split(s.string, "\n") } -func (c *CronString) parseAsSpec( +func (s *CronString) parseAsSpec( pattern string, hasUser bool, ) []cronSpec { envTable := make(map[string]string) specs := make([]cronSpec, 0) - lines := c.sanitize().lines() + lines := s.sanitize().lines() matcher, parser := buildMapper(hasUser, pattern) for _, line := range lines { @@ -98,11 +101,11 @@ func (c *CronString) parseAsSpec( return specs } -func (c *CronString) ParseConfig( +func (s *CronString) ParseConfig( pattern string, hasUser bool, ) *config.Config { - specs := c.parseAsSpec(pattern, hasUser) + specs := s.parseAsSpec(pattern, hasUser) cfg := &config.Config{} for _, spec := range specs { addSpec(cfg, spec) diff --git a/cmd/parser/parser.go b/cmd/parser/parser.go index e0ef610..b8baf74 100644 --- a/cmd/parser/parser.go +++ b/cmd/parser/parser.go @@ -1,3 +1,5 @@ +// Package parser manages holds the logic behind the sub command `parse` +// this package is responsible for parsing a crontab file into valid config yaml file package parser import ( diff --git a/test.yaml b/test.yaml deleted file mode 100644 index ae55495..0000000 --- a/test.yaml +++ /dev/null @@ -1,49 +0,0 @@ -jobs: - - description: Imported from cron file - events: - - cron: '* * * * *' - hooks: {} - name: 'FromCron: * * * * *' - tasks: - - command: php -v --help - env: - PATH: C:\xampp\php; - user: tng - - command: php -v --help --params - env: - PATH: C:\xampp\php; - user: tng - - description: Imported from cron file - events: - - cron: 0 0 * * * - hooks: {} - name: 'FromCron: 0 0 * * *' - tasks: - - command: php -v --help --params - env: - PATH: C:\xampp\php; - user: tng - - command: php -v --help --params - env: - PATH: C:\xampp\php; - user: tng - - description: Imported from cron file - events: - - cron: 0 0 */2 * * - hooks: {} - name: 'FromCron: 0 0 */2 * *' - tasks: - - command: php -v --help --params - env: - PATH: C:\xampp\php; - user: tng -escription: Imported from cron file - events: - - cron: 0 0 */2 * * - hooks: {} - name: 'FromCron: 0 0 */2 * *' - tasks: - - command: php -v --help --params - env: - PATH: C:\xampp\php; - user: tng