rule :: Rule args
rule = customRule check (emptyState NoCmd)
  where
    code = "DL4003"
    severity = DLWarningC
    message =
      "Multiple `CMD` instructions found. If you list more than one `CMD` then only the last \
      \`CMD` will take effect"

    -- Reset the state each time we find a FROM
    check _ st From {} = st |> replaceWith NoCmd
    -- Remember we found a CMD, fail if we found a CMD before
    check _ st@(State _ NoCmd) Cmd {} = st |> replaceWith HasCmd
    -- If we already saw a CMD, add an error for the line
    check line st@(State _ HasCmd) Cmd {} = st |> addFail (CheckFailure {..})
    -- otherwise return the accumulator
    check _ st _ = st

rule :: Rule args
rule = customRule check (emptyState NoCmd)
  where
    code = "DL4003"
    severity = DLWarningC
    message =
      "Multiple `CMD` instructions found. If you list more than one `CMD` then only the last \
      \`CMD` will take effect"

    -- Reset the state each time we find a FROM
    check _ st From {} = st |> replaceWith NoCmd
    -- Remember we found a CMD, fail if we found a CMD before
    check _ st@(State _ NoCmd) Cmd {} = st |> replaceWith HasCmd
    -- If we already saw a CMD, add an error for the line
    check line st@(State _ HasCmd) Cmd {} = st |> addFail (CheckFailure {..})
    -- otherwise return the accumulator
    check _ st _ = st

rule = customRule check (emptyState NoCmd)
  where
    code = "DL4003"
    severity = DLWarningC
    message =
      "Multiple `CMD` instructions found. If you list more than one `CMD` then only the last \
      \`CMD` will take effect"

    -- Reset the state each time we find a FROM
    check _ st From {} = st |> replaceWith NoCmd
    -- Remember we found a CMD, fail if we found a CMD before
    check _ st@(State _ NoCmd) Cmd {} = st |> replaceWith HasCmd
    -- If we already saw a CMD, add an error for the line
    check line st@(State _ HasCmd) Cmd {} = st |> addFail (CheckFailure {..})
    -- otherwise return the accumulator
    check _ st _ = st
