encapsule-0.6.1: src/Command.hs
-- SPDX-License-Identifier: Apache-2.0
module Command (defaultCommand, withInit) where
import Data.List (intercalate)
defaultCommand :: [String] -> [String]
defaultCommand [] = ["bash", "-l"]
defaultCommand command = command
-- Run init snippets as the container user, then replace Bash with the command.
-- Pass argv separately so Bash does not reinterpret command arguments as code.
withInit :: [String] -> [String] -> [String]
withInit [] command = command
withInit snippets command =
["bash", "-c", intercalate " && " (map block snippets ++ ["exec \"$@\""])]
++ "bash" : command -- $0 + $* are args passed to the -c script
where
-- Permit empty snippets; keep comments from swallowing the next command.
block snippet = "{\n:\n" ++ snippet ++ "\n}"