MarshalJSON implements custom JSON marshaling to expose all necessary fields
()
| 554 | |
| 555 | // MarshalJSON implements custom JSON marshaling to expose all necessary fields |
| 556 | func (l Line) MarshalJSON() ([]byte, error) { |
| 557 | type Alias Line |
| 558 | |
| 559 | // Base structure that all lines will have |
| 560 | base := struct { |
| 561 | Alias |
| 562 | IsJob bool `json:"is_job"` |
| 563 | IsComment bool `json:"is_comment"` |
| 564 | IsEnvVar bool `json:"is_env_var"` |
| 565 | Name string `json:"name"` |
| 566 | LineText string `json:"line_text"` |
| 567 | LineNumber int `json:"line_number"` |
| 568 | CronExpression string `json:"cron_expression"` |
| 569 | CommandToRun string `json:"command_to_run"` |
| 570 | Code string `json:"code"` |
| 571 | RunAs string `json:"run_as"` |
| 572 | Ignored bool `json:"ignored"` |
| 573 | EnvVarKey string `json:"env_var_key,omitempty"` |
| 574 | EnvVarValue string `json:"env_var_value,omitempty"` |
| 575 | Key string `json:"key,omitempty"` |
| 576 | CrontabFilename string `json:"crontab_filename,omitempty"` |
| 577 | DefaultName string `json:"default_name,omitempty"` |
| 578 | }{ |
| 579 | Alias: Alias(l), |
| 580 | IsJob: l.IsJob, |
| 581 | IsComment: l.IsComment, |
| 582 | IsEnvVar: l.IsEnvVar(), |
| 583 | Name: l.Name, |
| 584 | LineText: l.FullLine, |
| 585 | LineNumber: l.LineNumber, |
| 586 | CronExpression: l.CronExpression, |
| 587 | CommandToRun: l.CommandToRun, |
| 588 | Code: l.Code, |
| 589 | RunAs: l.RunAs, |
| 590 | Ignored: l.Ignored, |
| 591 | EnvVarKey: l.GetEnvVarKey(), |
| 592 | EnvVarValue: l.GetEnvVarValue(), |
| 593 | } |
| 594 | |
| 595 | // If this is a job, add additional fields |
| 596 | if l.IsJob { |
| 597 | base.Key = l.Key(l.Crontab.CanonicalName()) |
| 598 | base.CrontabFilename = l.Crontab.Filename |
| 599 | |
| 600 | // Generate default name |
| 601 | defaultName := "" |
| 602 | excludeFromName := []string{ |
| 603 | "2>&1", |
| 604 | "/bin/bash -l -c", |
| 605 | "/bin/bash -lc", |
| 606 | "/bin/bash -c -l", |
| 607 | "/bin/bash -cl", |
| 608 | "/dev/null", |
| 609 | "'", |
| 610 | "\"", |
| 611 | "\\", |
| 612 | } |
| 613 |
nothing calls this directly
no test coverage detected