module Hadolint.Rule.DL3034 (rule) where

import Hadolint.Rule
import qualified Hadolint.Shell as Shell
import Language.Docker.Syntax

rule :: Rule Shell.ParsedShell
rule :: Rule ParsedShell
rule = RuleCode
-> DLSeverity
-> Text
-> (Instruction ParsedShell -> Bool)
-> Rule ParsedShell
forall args.
RuleCode
-> DLSeverity -> Text -> (Instruction args -> Bool) -> Rule args
simpleRule RuleCode
code DLSeverity
severity Text
message Instruction ParsedShell -> Bool
check
  where
    code :: RuleCode
code = RuleCode
"DL3034"
    severity :: DLSeverity
severity = DLSeverity
DLWarningC
    message :: Text
message = Text
"Non-interactive switch missing from `zypper` command: `zypper install -y`"

    check :: Instruction ParsedShell -> Bool
check (Run (RunArgs Arguments ParsedShell
args RunFlags
_)) = (ParsedShell -> Bool) -> Arguments ParsedShell -> Bool
forall a b. (a -> b) -> Arguments a -> b
foldArguments ((Command -> Bool) -> ParsedShell -> Bool
Shell.noCommands Command -> Bool
forgotZypperYesOption) Arguments ParsedShell
args
    check Instruction ParsedShell
_ = Bool
True

    forgotZypperYesOption :: Command -> Bool
forgotZypperYesOption Command
cmd = Command -> Bool
isZypperInstall Command
cmd Bool -> Bool -> Bool
&& Bool -> Bool
not (Command -> Bool
hasYesOption Command
cmd)
    isZypperInstall :: Command -> Bool
isZypperInstall =
      Text -> [Text] -> Command -> Bool
Shell.cmdHasArgs
        Text
"zypper"
        [ Text
"install",
          Text
"in",
          Text
"remove",
          Text
"rm",
          Text
"source-install",
          Text
"si",
          Text
"patch"
        ]
    hasYesOption :: Command -> Bool
hasYesOption = [Text] -> Command -> Bool
Shell.hasAnyFlag [Text
"non-interactive", Text
"n", Text
"no-confirm", Text
"y"]
{-# INLINEABLE rule #-}