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

Method MarshalJSON

lib/crontab.go:556–760  ·  view source on GitHub ↗

MarshalJSON implements custom JSON marshaling to expose all necessary fields

()

Source from the content-addressed store, hash-verified

554
555// MarshalJSON implements custom JSON marshaling to expose all necessary fields
556func (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

Callers

nothing calls this directly

Calls 9

IsEnvVarMethod · 0.95
GetEnvVarKeyMethod · 0.95
GetEnvVarValueMethod · 0.95
KeyMethod · 0.95
IsAutoDiscoverCommandMethod · 0.95
IsMetaCronJobMethod · 0.95
AliasTypeAlias · 0.85
CanonicalNameMethod · 0.80
DisplayNameMethod · 0.80

Tested by

no test coverage detected