module Hadolint.Rule.DL3014 (rule) where

import Hadolint.Rule
import Hadolint.Shell (ParsedShell)
import qualified Hadolint.Shell as Shell
import Language.Docker.Syntax


rule :: Rule ParsedShell
rule :: Rule ParsedShell
rule = Rule ParsedShell
dl3014 forall a. Semigroup a => a -> a -> a
<> forall args. Rule args -> Rule args
onbuild Rule ParsedShell
dl3014
{-# INLINEABLE rule #-}

dl3014 :: Rule ParsedShell
dl3014 :: Rule ParsedShell
dl3014 = 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
"DL3014"
    severity :: DLSeverity
severity = DLSeverity
DLWarningC
    message :: Text
message = Text
"Use the `-y` switch to avoid manual input `apt-get -y install <package>`"

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

    forgotAptYesOption :: Command -> Bool
forgotAptYesOption Command
cmd = Command -> Bool
isAptGetInstall Command
cmd Bool -> Bool -> Bool
&& Bool -> Bool
not (Command -> Bool
hasYesOption Command
cmd)
    isAptGetInstall :: Command -> Bool
isAptGetInstall = Text -> [Text] -> Command -> Bool
Shell.cmdHasArgs Text
"apt-get" [Text
"install"]
    hasYesOption :: Command -> Bool
hasYesOption = [Text] -> Command -> Bool
Shell.hasAnyFlag [Text
"y", Text
"yes", Text
"q", Text
"assume-yes"]
{-# INLINEABLE dl3014 #-}