(inlineArgs []string, cfg *config.Map)
| 94 | } |
| 95 | |
| 96 | func (c *Check) Configure(inlineArgs []string, cfg *config.Map) error { |
| 97 | if len(inlineArgs) == 0 { |
| 98 | return errors.New("command: at least one argument is required (command name)") |
| 99 | } |
| 100 | |
| 101 | c.cmd = inlineArgs[0] |
| 102 | c.cmdArgs = inlineArgs[1:] |
| 103 | |
| 104 | // Check whether the inline argument command is usable. |
| 105 | if _, err := exec.LookPath(c.cmd); err != nil { |
| 106 | return fmt.Errorf("command: %w", err) |
| 107 | } |
| 108 | |
| 109 | cfg.Enum("run_on", false, false, |
| 110 | []string{StageConnection, StageSender, StageRcpt, StageBody}, StageBody, |
| 111 | (*string)(&c.stage)) |
| 112 | |
| 113 | cfg.AllowUnknown() |
| 114 | unknown, err := cfg.Process() |
| 115 | if err != nil { |
| 116 | return err |
| 117 | } |
| 118 | |
| 119 | for _, node := range unknown { |
| 120 | switch node.Name { |
| 121 | case "code": |
| 122 | if len(node.Args) < 2 { |
| 123 | return config.NodeErr(node, "at least two arguments are required: <code> <action>") |
| 124 | } |
| 125 | exitCode, err := strconv.Atoi(node.Args[0]) |
| 126 | if err != nil { |
| 127 | return config.NodeErr(node, "%v", err) |
| 128 | } |
| 129 | action, err := modconfig.ParseActionDirective(node.Args[1:]) |
| 130 | if err != nil { |
| 131 | return config.NodeErr(node, "%v", err) |
| 132 | } |
| 133 | |
| 134 | c.actions[exitCode] = action |
| 135 | default: |
| 136 | return config.NodeErr(node, "unexpected directive: %v", node.Name) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | type state struct { |
| 144 | c *Check |
nothing calls this directly
no test coverage detected