{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NoMonomorphismRestriction #-}

module Language.Docker.PrettyPrint where

import Data.List.NonEmpty as NonEmpty (NonEmpty (..), toList)
import Data.Set (Set)
import Data.String (fromString)
import Data.Text (Text)
import Prettyprinter
import Prettyprinter.Internal (Doc (Empty))
import Prettyprinter.Render.Text (renderLazy)
import Language.Docker.Syntax
import Prelude hiding ((<>), (>>))
import qualified Data.Set as Set
import qualified Data.Text as Text
import qualified Data.Text.Lazy as L
import qualified Data.Text.Lazy.Builder as B

data EscapeAccum
  = EscapeAccum
      { EscapeAccum -> Builder
buffer :: !B.Builder,
        EscapeAccum -> Int
count :: !Int,
        EscapeAccum -> Bool
escaping :: !Bool
      }

-- | Pretty print a 'Dockerfile' to a 'Text'
prettyPrint :: Dockerfile -> L.Text
prettyPrint :: Dockerfile -> Text
prettyPrint = SimpleDocStream Any -> Text
forall ann. SimpleDocStream ann -> Text
renderLazy (SimpleDocStream Any -> Text)
-> (Dockerfile -> SimpleDocStream Any) -> Dockerfile -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayoutOptions -> Doc Any -> SimpleDocStream Any
forall ann. LayoutOptions -> Doc ann -> SimpleDocStream ann
layoutPretty LayoutOptions
opts (Doc Any -> SimpleDocStream Any)
-> (Dockerfile -> Doc Any) -> Dockerfile -> SimpleDocStream Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dockerfile -> Doc Any
forall ann. Dockerfile -> Doc ann
prettyPrintDockerfile
  where
    opts :: LayoutOptions
opts = PageWidth -> LayoutOptions
LayoutOptions PageWidth
Unbounded

prettyPrintDockerfile :: [InstructionPos Text] -> Doc ann
prettyPrintDockerfile :: forall ann. Dockerfile -> Doc ann
prettyPrintDockerfile Dockerfile
instr = Dockerfile -> Doc ann
forall ann. Dockerfile -> Doc ann
doPrint Dockerfile
instr Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"\n"
  where
    doPrint :: Dockerfile -> Doc ann
doPrint Dockerfile
ips =
      let ?esc = Dockerfile -> Char
forall args. [InstructionPos args] -> Char
findEscapeChar Dockerfile
ips
       in ([Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep ([Doc ann] -> Doc ann)
-> (Dockerfile -> [Doc ann]) -> Dockerfile -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (InstructionPos Text -> Doc ann) -> Dockerfile -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap InstructionPos Text -> Doc ann
forall ann. (?esc::Char) => InstructionPos Text -> Doc ann
prettyPrintInstructionPos ) Dockerfile
ips

findEscapeChar ::  [InstructionPos args] -> Char
findEscapeChar :: forall args. [InstructionPos args] -> Char
findEscapeChar [] = Char
defaultEsc
findEscapeChar (InstructionPos args
i:[InstructionPos args]
is) =
  case InstructionPos args
i of
    InstructionPos {$sel:instruction:InstructionPos :: forall args. InstructionPos args -> Instruction args
instruction = (Pragma (Escape (EscapeChar Char
c)))} -> Char
c
    InstructionPos {$sel:instruction:InstructionPos :: forall args. InstructionPos args -> Instruction args
instruction = (Pragma PragmaDirective
_)} -> [InstructionPos args] -> Char
forall args. [InstructionPos args] -> Char
findEscapeChar [InstructionPos args]
is
    InstructionPos args
_ -> Char
defaultEsc

-- | Pretty print a 'InstructionPos' to a 'Doc'
prettyPrintInstructionPos :: (?esc :: Char) => InstructionPos Text -> Doc ann
prettyPrintInstructionPos :: forall ann. (?esc::Char) => InstructionPos Text -> Doc ann
prettyPrintInstructionPos (InstructionPos Instruction Text
i Text
_ Int
_) = Instruction Text -> Doc ann
forall ann. (?esc::Char) => Instruction Text -> Doc ann
prettyPrintInstruction Instruction Text
i

prettyPrintImage :: Image -> Doc ann
prettyPrintImage :: forall ann. Image -> Doc ann
prettyPrintImage (Image Maybe Registry
Nothing Text
name) = Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
name
prettyPrintImage (Image (Just (Registry Text
reg)) Text
name) = Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
reg Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"/" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
name

prettyPrintBaseImage :: BaseImage -> Doc ann
prettyPrintBaseImage :: forall ann. BaseImage -> Doc ann
prettyPrintBaseImage BaseImage {Maybe Text
Maybe ImageAlias
Maybe Digest
Maybe Tag
Image
image :: Image
tag :: Maybe Tag
digest :: Maybe Digest
alias :: Maybe ImageAlias
platform :: Maybe Text
$sel:image:BaseImage :: BaseImage -> Image
$sel:tag:BaseImage :: BaseImage -> Maybe Tag
$sel:digest:BaseImage :: BaseImage -> Maybe Digest
$sel:alias:BaseImage :: BaseImage -> Maybe ImageAlias
$sel:platform:BaseImage :: BaseImage -> Maybe Text
..} = do
  Maybe Text -> Doc ann
forall {a} {ann}. Pretty a => Maybe a -> Doc ann
prettyPlatform Maybe Text
platform
  Image -> Doc ann
forall ann. Image -> Doc ann
prettyPrintImage Image
image
  Maybe Tag -> Doc ann
forall {ann}. Maybe Tag -> Doc ann
prettyTag Maybe Tag
tag
  Maybe Digest -> Doc ann
forall {ann}. Maybe Digest -> Doc ann
prettyDigest Maybe Digest
digest
  Maybe ImageAlias -> Doc ann
forall {ann}. Maybe ImageAlias -> Doc ann
prettyAlias Maybe ImageAlias
alias
  where
    >> :: a -> a -> a
(>>) = a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>)
    prettyPlatform :: Maybe a -> Doc ann
prettyPlatform Maybe a
maybePlatform =
      case Maybe a
maybePlatform of
        Maybe a
Nothing -> Doc ann
forall a. Monoid a => a
mempty
        Just a
p -> Doc ann
"--platform=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> a -> Doc ann
forall ann. a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty a
p Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
" "
    prettyTag :: Maybe Tag -> Doc ann
prettyTag Maybe Tag
maybeTag =
      case Maybe Tag
maybeTag of
        Maybe Tag
Nothing -> Doc ann
forall a. Monoid a => a
mempty
        Just (Tag Text
p) -> Doc ann
":" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
p
    prettyAlias :: Maybe ImageAlias -> Doc ann
prettyAlias Maybe ImageAlias
maybeAlias =
      case Maybe ImageAlias
maybeAlias of
        Maybe ImageAlias
Nothing -> Doc ann
forall a. Monoid a => a
mempty
        Just (ImageAlias Text
a) -> Doc ann
" AS " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
a
    prettyDigest :: Maybe Digest -> Doc ann
prettyDigest Maybe Digest
maybeDigest =
      case Maybe Digest
maybeDigest of
        Maybe Digest
Nothing -> Doc ann
forall a. Monoid a => a
mempty
        Just (Digest Text
d) -> Doc ann
"@" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
d

prettyPrintPairs :: (?esc :: Char) => Pairs -> Doc ann
prettyPrintPairs :: forall ann. (?esc::Char) => Pairs -> Doc ann
prettyPrintPairs Pairs
ps = Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
align (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann] -> Doc ann
forall {t :: * -> *} {a} {ann}.
(Foldable t, Pretty a, ?esc::a) =>
t (Doc ann) -> Doc ann
sepLine ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$ ((Text, Text) -> Doc ann) -> Pairs -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text, Text) -> Doc ann
forall ann. (?esc::Char) => (Text, Text) -> Doc ann
prettyPrintPair Pairs
ps
  where
    sepLine :: t (Doc ann) -> Doc ann
sepLine = (Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
forall (t :: * -> *) ann.
Foldable t =>
(Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith (\Doc ann
x Doc ann
y -> Doc ann
x Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
" " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> a -> Doc ann
forall ann. a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty a
?esc::a
?esc Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
forall ann. Doc ann
line Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
y)

prettyPrintPair :: (?esc :: Char) => (Text, Text) -> Doc ann
prettyPrintPair :: forall ann. (?esc::Char) => (Text, Text) -> Doc ann
prettyPrintPair (Text
k, Text
v) = Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
k Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Char -> Doc ann
forall ann. Char -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Char
'=' Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
doubleQoute Text
v

prettyPrintArguments :: (?esc :: Char) => Arguments Text -> Doc ann
prettyPrintArguments :: forall ann. (?esc::Char) => Arguments Text -> Doc ann
prettyPrintArguments (ArgumentsList Text
as) = [Text] -> Doc ann
forall ann. (?esc::Char) => [Text] -> Doc ann
prettyPrintJSON (Text -> [Text]
Text.words Text
as)
prettyPrintArguments (ArgumentsText Text
as) = [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep ((Text -> Doc ann) -> [Text] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Doc ann
forall {a} {a} {ann}.
(Eq a, IsString a, ?esc::a, Pretty a, Pretty a) =>
a -> Doc ann
helper (Text -> [Text]
Text.words Text
as))
  where
    helper :: a -> Doc ann
helper a
"&&" = a -> Doc ann
forall ann. a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty a
?esc::a
?esc Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"\n &&"
    helper a
a = a -> Doc ann
forall ann. a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty a
a

prettyPrintJSON :: (?esc :: Char) => [Text] -> Doc ann
prettyPrintJSON :: forall ann. (?esc::Char) => [Text] -> Doc ann
prettyPrintJSON [Text]
args = [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
list ((Text -> Doc ann) -> [Text] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
doubleQoute [Text]
args)

doubleQoute :: (?esc :: Char) => Text -> Doc ann
doubleQoute :: forall ann. (?esc::Char) => Text -> Doc ann
doubleQoute Text
w = Doc ann -> Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann -> Doc ann
enclose Doc ann
forall ann. Doc ann
dquote Doc ann
forall ann. Doc ann
dquote (Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ((?esc::Char) => Text -> Text
Text -> Text
escapeQuotes Text
w))

escapeQuotes :: (?esc :: Char) => Text -> L.Text
escapeQuotes :: (?esc::Char) => Text -> Text
escapeQuotes Text
text =
  case (Char -> EscapeAccum -> EscapeAccum)
-> EscapeAccum -> Text -> EscapeAccum
forall a. (Char -> a -> a) -> a -> Text -> a
Text.foldr (?esc::Char) => Char -> EscapeAccum -> EscapeAccum
Char -> EscapeAccum -> EscapeAccum
accumulate (Builder -> Int -> Bool -> EscapeAccum
EscapeAccum Builder
forall a. Monoid a => a
mempty Int
0 Bool
False) Text
text of
    EscapeAccum Builder
buffer Int
_ Bool
False -> Builder -> Text
B.toLazyText Builder
buffer
    EscapeAccum Builder
buffer Int
count Bool
True ->
      case Int
count Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
2 of
        Int
0 -> Builder -> Text
B.toLazyText (Char -> Builder
B.singleton ?esc::Char
Char
?esc Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
buffer)
        Int
_ -> Builder -> Text
B.toLazyText Builder
buffer
  where
    accumulate :: Char -> EscapeAccum -> EscapeAccum
accumulate Char
'"' EscapeAccum {Builder
$sel:buffer:EscapeAccum :: EscapeAccum -> Builder
buffer :: Builder
buffer, $sel:escaping:EscapeAccum :: EscapeAccum -> Bool
escaping = Bool
False} =
      Builder -> Int -> Bool -> EscapeAccum
EscapeAccum (Char -> Builder
B.singleton Char
'"' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
buffer) Int
0 Bool
True
    accumulate Char
c EscapeAccum {Builder
$sel:buffer:EscapeAccum :: EscapeAccum -> Builder
buffer :: Builder
buffer, $sel:escaping:EscapeAccum :: EscapeAccum -> Bool
escaping = Bool
True, Int
$sel:count:EscapeAccum :: EscapeAccum -> Int
count :: Int
count}
      | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ?esc::Char
Char
?esc = Builder -> Int -> Bool -> EscapeAccum
EscapeAccum (Char -> Builder
B.singleton ?esc::Char
Char
?esc Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
buffer) (Int
count Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Bool
True
      | Int -> Bool
forall a. Integral a => a -> Bool
even Int
count = Builder -> Int -> Bool -> EscapeAccum
EscapeAccum (Char -> Builder
B.singleton Char
c Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
B.singleton ?esc::Char
Char
?esc Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
buffer) Int
0 Bool
False
      | Bool
otherwise = Builder -> Int -> Bool -> EscapeAccum
EscapeAccum (Char -> Builder
B.singleton Char
c Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
buffer) Int
0 Bool
False -- It was already escaped
    accumulate Char
c EscapeAccum {Builder
$sel:buffer:EscapeAccum :: EscapeAccum -> Builder
buffer :: Builder
buffer, $sel:escaping:EscapeAccum :: EscapeAccum -> Bool
escaping = Bool
False} =
      Builder -> Int -> Bool -> EscapeAccum
EscapeAccum (Char -> Builder
B.singleton Char
c Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
buffer) Int
0 Bool
False

prettyPrintPortSpec :: PortSpec -> Doc ann
prettyPrintPortSpec :: forall ann. PortSpec -> Doc ann
prettyPrintPortSpec (PortSpec Port
port) = Port -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Port -> Doc ann
pretty Port
port
prettyPrintPortSpec (PortRangeSpec PortRange
portrange) = PortRange -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. PortRange -> Doc ann
pretty PortRange
portrange

prettyPrintFileList :: NonEmpty SourcePath -> TargetPath -> Doc ann
prettyPrintFileList :: forall ann. NonEmpty SourcePath -> TargetPath -> Doc ann
prettyPrintFileList NonEmpty SourcePath
sources (TargetPath Text
dest) =
  let ending :: a
ending =
        case (Text -> Text -> Bool
Text.isSuffixOf Text
"/" Text
dest, NonEmpty SourcePath
sources) of
          (Bool
True, NonEmpty SourcePath
_) -> a
"" -- If the target ends with / then no extra ending is needed
          (Bool
_, SourcePath
_fst :| SourcePath
_snd : [SourcePath]
_) -> a
"/" -- More than one source means that the target should end in /
          (Bool, NonEmpty SourcePath)
_ -> a
""
   in [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
s | SourcePath Text
s <- NonEmpty SourcePath -> [SourcePath]
forall a. NonEmpty a -> [a]
toList NonEmpty SourcePath
sources] [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. [a] -> [a] -> [a]
++ [Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
dest Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
forall {a}. IsString a => a
ending]

prettyPrintChecksum :: Checksum -> Doc ann
prettyPrintChecksum :: forall ann. Checksum -> Doc ann
prettyPrintChecksum Checksum
checksum =
  case Checksum
checksum of
    Checksum Text
c -> Doc ann
"--checksum=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
c
    Checksum
NoChecksum -> Doc ann
forall a. Monoid a => a
mempty

prettyPrintChown :: Chown -> Doc ann
prettyPrintChown :: forall ann. Chown -> Doc ann
prettyPrintChown Chown
chown =
  case Chown
chown of
    Chown Text
c -> Doc ann
"--chown=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
c
    Chown
NoChown -> Doc ann
forall a. Monoid a => a
mempty

prettyPrintChmod :: Chmod -> Doc ann
prettyPrintChmod :: forall ann. Chmod -> Doc ann
prettyPrintChmod Chmod
chmod =
  case Chmod
chmod of
    Chmod Text
c -> Doc ann
"--chmod=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
c
    Chmod
NoChmod -> Doc ann
forall a. Monoid a => a
mempty

prettyPrintLink :: Link -> Doc ann
prettyPrintLink :: forall ann. Link -> Doc ann
prettyPrintLink Link
link =
  case Link
link of
    Link
Link -> Doc ann
"--link"
    Link
NoLink -> Doc ann
forall a. Monoid a => a
mempty

prettyPrintCopySource :: CopySource -> Doc ann
prettyPrintCopySource :: forall ann. CopySource -> Doc ann
prettyPrintCopySource CopySource
source =
  case CopySource
source of
    CopySource Text
c -> Doc ann
"--from=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
c
    CopySource
NoSource -> Doc ann
forall a. Monoid a => a
mempty

prettyPrintDuration :: Text -> Maybe Duration -> Doc ann
prettyPrintDuration :: forall ann. Text -> Maybe Duration -> Doc ann
prettyPrintDuration Text
flagName = Doc ann -> (Duration -> Doc ann) -> Maybe Duration -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Duration -> Doc ann
forall {ann}. Duration -> Doc ann
pp
  where
    pp :: Duration -> Doc ann
pp (Duration DiffTime
d) = Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
flagName Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> String -> Doc ann
forall ann. String -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (DiffTime -> String
forall a. Show a => a -> String
show DiffTime
d)

prettyPrintRetries :: Maybe Retries -> Doc ann
prettyPrintRetries :: forall ann. Maybe Retries -> Doc ann
prettyPrintRetries = Doc ann -> (Retries -> Doc ann) -> Maybe Retries -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Retries -> Doc ann
forall {ann}. Retries -> Doc ann
pp
  where
    pp :: Retries -> Doc ann
pp (Retries Int
r) = Doc ann
"--retries=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Int -> Doc ann
forall ann. Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Int
r

prettyPrintRunMount :: (?esc :: Char) => Set RunMount -> Doc ann
prettyPrintRunMount :: forall ann. (?esc::Char) => Set RunMount -> Doc ann
prettyPrintRunMount Set RunMount
set =
  (Doc ann -> Doc ann -> Doc ann) -> Doc ann -> [Doc ann] -> Doc ann
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
(<>) Doc ann
"" ((RunMount -> Doc ann) -> [RunMount] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map RunMount -> Doc ann
forall {ann}. (?esc::Char) => RunMount -> Doc ann
printSingleMount (Set RunMount -> [RunMount]
forall a. Set a -> [a]
Set.toList Set RunMount
set))
  where
    printSingleMount :: RunMount -> Doc ann
printSingleMount RunMount
mount = Doc ann
"--mount="
      Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> case RunMount
mount of
        BindMount BindOpts {Maybe Bool
Maybe Text
Maybe SourcePath
TargetPath
bTarget :: TargetPath
bSource :: Maybe SourcePath
bFromImage :: Maybe Text
bReadOnly :: Maybe Bool
$sel:bTarget:BindOpts :: BindOpts -> TargetPath
$sel:bSource:BindOpts :: BindOpts -> Maybe SourcePath
$sel:bFromImage:BindOpts :: BindOpts -> Maybe Text
$sel:bReadOnly:BindOpts :: BindOpts -> Maybe Bool
..} ->
          Doc ann
"type=bind"
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> TargetPath -> Doc ann
forall {ann}. (?esc::Char) => TargetPath -> Doc ann
printTarget TargetPath
bTarget
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (SourcePath -> Doc ann) -> Maybe SourcePath -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty SourcePath -> Doc ann
forall {ann}. (?esc::Char) => SourcePath -> Doc ann
printSource Maybe SourcePath
bSource
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
printFromImage Maybe Text
bFromImage
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Bool -> Doc ann) -> Maybe Bool -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Bool -> Doc ann
forall {a}. IsString a => Bool -> a
printReadOnly Maybe Bool
bReadOnly
        CacheMount CacheOpts {Maybe Bool
Maybe Text
Maybe CacheSharing
Maybe SourcePath
TargetPath
cTarget :: TargetPath
cSharing :: Maybe CacheSharing
cCacheId :: Maybe Text
cReadOnly :: Maybe Bool
cFromImage :: Maybe Text
cSource :: Maybe SourcePath
cMode :: Maybe Text
cUid :: Maybe Text
cGid :: Maybe Text
$sel:cTarget:CacheOpts :: CacheOpts -> TargetPath
$sel:cSharing:CacheOpts :: CacheOpts -> Maybe CacheSharing
$sel:cCacheId:CacheOpts :: CacheOpts -> Maybe Text
$sel:cReadOnly:CacheOpts :: CacheOpts -> Maybe Bool
$sel:cFromImage:CacheOpts :: CacheOpts -> Maybe Text
$sel:cSource:CacheOpts :: CacheOpts -> Maybe SourcePath
$sel:cMode:CacheOpts :: CacheOpts -> Maybe Text
$sel:cUid:CacheOpts :: CacheOpts -> Maybe Text
$sel:cGid:CacheOpts :: CacheOpts -> Maybe Text
..} ->
          Doc ann
"type=cache"
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> TargetPath -> Doc ann
forall {ann}. (?esc::Char) => TargetPath -> Doc ann
printTarget TargetPath
cTarget
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
-> (CacheSharing -> Doc ann) -> Maybe CacheSharing -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty CacheSharing -> Doc ann
forall {a}. (Semigroup a, IsString a) => CacheSharing -> a
printSharing Maybe CacheSharing
cSharing
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
printId Maybe Text
cCacheId
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
printFromImage Maybe Text
cFromImage
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (SourcePath -> Doc ann) -> Maybe SourcePath -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty SourcePath -> Doc ann
forall {ann}. (?esc::Char) => SourcePath -> Doc ann
printSource Maybe SourcePath
cSource
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall {a} {ann}. Pretty a => a -> Doc ann
printMode Maybe Text
cMode
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall {a} {ann}. Pretty a => a -> Doc ann
printUid Maybe Text
cUid
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall {a} {ann}. Pretty a => a -> Doc ann
printGid Maybe Text
cGid
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Bool -> Doc ann) -> Maybe Bool -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Bool -> Doc ann
forall {a}. IsString a => Bool -> a
printReadOnly Maybe Bool
cReadOnly
        SshMount SecretOpts {Maybe Bool
Maybe Text
Maybe TargetPath
Maybe SourcePath
sTarget :: Maybe TargetPath
sCacheId :: Maybe Text
sIsRequired :: Maybe Bool
sSource :: Maybe SourcePath
sMode :: Maybe Text
sUid :: Maybe Text
sGid :: Maybe Text
$sel:sTarget:SecretOpts :: SecretOpts -> Maybe TargetPath
$sel:sCacheId:SecretOpts :: SecretOpts -> Maybe Text
$sel:sIsRequired:SecretOpts :: SecretOpts -> Maybe Bool
$sel:sSource:SecretOpts :: SecretOpts -> Maybe SourcePath
$sel:sMode:SecretOpts :: SecretOpts -> Maybe Text
$sel:sUid:SecretOpts :: SecretOpts -> Maybe Text
$sel:sGid:SecretOpts :: SecretOpts -> Maybe Text
..} ->
          Doc ann
"type=ssh"
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (TargetPath -> Doc ann) -> Maybe TargetPath -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty TargetPath -> Doc ann
forall {ann}. (?esc::Char) => TargetPath -> Doc ann
printTarget Maybe TargetPath
sTarget
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
printId Maybe Text
sCacheId
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (SourcePath -> Doc ann) -> Maybe SourcePath -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty SourcePath -> Doc ann
forall {ann}. (?esc::Char) => SourcePath -> Doc ann
printSource Maybe SourcePath
sSource
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall {a} {ann}. Pretty a => a -> Doc ann
printMode Maybe Text
sMode
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall {a} {ann}. Pretty a => a -> Doc ann
printUid Maybe Text
sUid
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall {a} {ann}. Pretty a => a -> Doc ann
printGid Maybe Text
sGid
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Bool -> Doc ann) -> Maybe Bool -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Bool -> Doc ann
forall {a}. (IsString a, Monoid a) => Bool -> a
printRequired Maybe Bool
sIsRequired
        SecretMount SecretOpts {Maybe Bool
Maybe Text
Maybe TargetPath
Maybe SourcePath
$sel:sTarget:SecretOpts :: SecretOpts -> Maybe TargetPath
$sel:sCacheId:SecretOpts :: SecretOpts -> Maybe Text
$sel:sIsRequired:SecretOpts :: SecretOpts -> Maybe Bool
$sel:sSource:SecretOpts :: SecretOpts -> Maybe SourcePath
$sel:sMode:SecretOpts :: SecretOpts -> Maybe Text
$sel:sUid:SecretOpts :: SecretOpts -> Maybe Text
$sel:sGid:SecretOpts :: SecretOpts -> Maybe Text
sTarget :: Maybe TargetPath
sCacheId :: Maybe Text
sIsRequired :: Maybe Bool
sSource :: Maybe SourcePath
sMode :: Maybe Text
sUid :: Maybe Text
sGid :: Maybe Text
..} ->
          Doc ann
"type=secret"
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (TargetPath -> Doc ann) -> Maybe TargetPath -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty TargetPath -> Doc ann
forall {ann}. (?esc::Char) => TargetPath -> Doc ann
printTarget Maybe TargetPath
sTarget
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
printId Maybe Text
sCacheId
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (SourcePath -> Doc ann) -> Maybe SourcePath -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty SourcePath -> Doc ann
forall {ann}. (?esc::Char) => SourcePath -> Doc ann
printSource Maybe SourcePath
sSource
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall {a} {ann}. Pretty a => a -> Doc ann
printMode Maybe Text
sMode
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall {a} {ann}. Pretty a => a -> Doc ann
printUid Maybe Text
sUid
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Text -> Doc ann) -> Maybe Text -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Text -> Doc ann
forall {a} {ann}. Pretty a => a -> Doc ann
printGid Maybe Text
sGid
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> (Bool -> Doc ann) -> Maybe Bool -> Doc ann
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc ann
forall a. Monoid a => a
mempty Bool -> Doc ann
forall {a}. (IsString a, Monoid a) => Bool -> a
printRequired Maybe Bool
sIsRequired
        TmpfsMount TmpOpts {TargetPath
tTarget :: TargetPath
$sel:tTarget:TmpOpts :: TmpOpts -> TargetPath
..} -> Doc ann
"type=tmpfs" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> TargetPath -> Doc ann
forall {ann}. (?esc::Char) => TargetPath -> Doc ann
printTarget TargetPath
tTarget
    printQuotable :: Text -> Doc ann
printQuotable Text
str
      | (Char -> Bool) -> Text -> Bool
Text.any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'"') Text
str = Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
doubleQoute Text
str
      | Bool
otherwise = Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
str
    printTarget :: TargetPath -> Doc ann
printTarget (TargetPath Text
t) = Doc ann
",target=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
printQuotable Text
t
    printSource :: SourcePath -> Doc ann
printSource (SourcePath Text
s) = Doc ann
",source=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
printQuotable Text
s
    printFromImage :: Text -> Doc ann
printFromImage Text
f = Doc ann
",from=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
printQuotable Text
f
    printSharing :: CacheSharing -> a
printSharing CacheSharing
sharing = a
",sharing="
      a -> a -> a
forall a. Semigroup a => a -> a -> a
<> case CacheSharing
sharing of
        CacheSharing
Shared -> a
"shared"
        CacheSharing
Private -> a
"private"
        CacheSharing
Locked -> a
"locked"
    printId :: Text -> Doc ann
printId Text
i = Doc ann
",id=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. (?esc::Char) => Text -> Doc ann
printQuotable Text
i
    printMode :: a -> Doc ann
printMode a
m = Doc ann
",mode=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> a -> Doc ann
forall ann. a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty a
m
    printUid :: a -> Doc ann
printUid a
uid = Doc ann
",uid=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> a -> Doc ann
forall ann. a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty a
uid
    printGid :: a -> Doc ann
printGid a
gid = Doc ann
",gid=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> a -> Doc ann
forall ann. a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty a
gid
    printReadOnly :: Bool -> a
printReadOnly Bool
True = a
",ro"
    printReadOnly Bool
False = a
",rw"
    printRequired :: Bool -> a
printRequired Bool
True = a
",required"
    printRequired Bool
False = a
forall a. Monoid a => a
mempty

prettyPrintRunNetwork :: Maybe RunNetwork -> Doc ann
prettyPrintRunNetwork :: forall ann. Maybe RunNetwork -> Doc ann
prettyPrintRunNetwork Maybe RunNetwork
Nothing = Doc ann
forall a. Monoid a => a
mempty
prettyPrintRunNetwork (Just RunNetwork
NetworkHost) = Doc ann
"--network=host"
prettyPrintRunNetwork (Just RunNetwork
NetworkNone) = Doc ann
"--network=none"
prettyPrintRunNetwork (Just RunNetwork
NetworkDefault) = Doc ann
"--network=default"

prettyPrintRunSecurity :: Maybe RunSecurity -> Doc ann
prettyPrintRunSecurity :: forall ann. Maybe RunSecurity -> Doc ann
prettyPrintRunSecurity Maybe RunSecurity
Nothing = Doc ann
forall a. Monoid a => a
mempty
prettyPrintRunSecurity (Just RunSecurity
Sandbox) = Doc ann
"--security=sandbox"
prettyPrintRunSecurity (Just RunSecurity
Insecure) = Doc ann
"--security=insecure"

prettyPrintPragma :: PragmaDirective -> Doc ann
prettyPrintPragma :: forall ann. PragmaDirective -> Doc ann
prettyPrintPragma (Escape (EscapeChar Char
esc)) = Doc ann
"escape = " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Char -> Doc ann
forall ann. Char -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Char
esc
prettyPrintPragma (Syntax (SyntaxImage Image
img)) = Doc ann
"syntax = " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Image -> Doc ann
forall ann. Image -> Doc ann
prettyPrintImage Image
img

prettyPrintInstruction :: (?esc :: Char) => Instruction Text -> Doc ann
prettyPrintInstruction :: forall ann. (?esc::Char) => Instruction Text -> Doc ann
prettyPrintInstruction Instruction Text
i =
  case Instruction Text
i of
    Maintainer Text
m -> do
      Doc ann
"MAINTAINER"
      Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
m
    Arg Text
a Maybe Text
Nothing -> do
      Doc ann
"ARG"
      Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
a
    Arg Text
k (Just Text
v) -> do
      Doc ann
"ARG"
      Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
k Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"=" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
v
    Entrypoint Arguments Text
e -> do
      Doc ann
"ENTRYPOINT"
      Arguments Text -> Doc ann
forall ann. (?esc::Char) => Arguments Text -> Doc ann
prettyPrintArguments Arguments Text
e
    Stopsignal Text
s -> do
      Doc ann
"STOPSIGNAL"
      Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
s
    Workdir Text
w -> do
      Doc ann
"WORKDIR"
      Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
w
    Expose (Ports [PortSpec]
ps) -> do
      Doc ann
"EXPOSE"
      [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep ((PortSpec -> Doc ann) -> [PortSpec] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PortSpec -> Doc ann
forall ann. PortSpec -> Doc ann
prettyPrintPortSpec [PortSpec]
ps)
    Volume Text
dir -> do
      Doc ann
"VOLUME"
      Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
dir
    Run (RunArgs Arguments Text
c RunFlags {Set RunMount
mount :: Set RunMount
$sel:mount:RunFlags :: RunFlags -> Set RunMount
mount, Maybe RunNetwork
network :: Maybe RunNetwork
$sel:network:RunFlags :: RunFlags -> Maybe RunNetwork
network, Maybe RunSecurity
security :: Maybe RunSecurity
$sel:security:RunFlags :: RunFlags -> Maybe RunSecurity
security}) -> do
      Doc ann
"RUN"
      Set RunMount -> Doc ann
forall ann. (?esc::Char) => Set RunMount -> Doc ann
prettyPrintRunMount Set RunMount
mount
      Maybe RunNetwork -> Doc ann
forall ann. Maybe RunNetwork -> Doc ann
prettyPrintRunNetwork Maybe RunNetwork
network
      Maybe RunSecurity -> Doc ann
forall ann. Maybe RunSecurity -> Doc ann
prettyPrintRunSecurity Maybe RunSecurity
security
      Arguments Text -> Doc ann
forall ann. (?esc::Char) => Arguments Text -> Doc ann
prettyPrintArguments Arguments Text
c
    Copy
      CopyArgs {NonEmpty SourcePath
sourcePaths :: NonEmpty SourcePath
$sel:sourcePaths:CopyArgs :: CopyArgs -> NonEmpty SourcePath
sourcePaths, TargetPath
targetPath :: TargetPath
$sel:targetPath:CopyArgs :: CopyArgs -> TargetPath
targetPath}
      CopyFlags {Chmod
chmodFlag :: Chmod
$sel:chmodFlag:CopyFlags :: CopyFlags -> Chmod
chmodFlag, Chown
chownFlag :: Chown
$sel:chownFlag:CopyFlags :: CopyFlags -> Chown
chownFlag, Link
linkFlag :: Link
$sel:linkFlag:CopyFlags :: CopyFlags -> Link
linkFlag, CopySource
sourceFlag :: CopySource
$sel:sourceFlag:CopyFlags :: CopyFlags -> CopySource
sourceFlag} -> do
        Doc ann
"COPY"
        Chown -> Doc ann
forall ann. Chown -> Doc ann
prettyPrintChown Chown
chownFlag
        Chmod -> Doc ann
forall ann. Chmod -> Doc ann
prettyPrintChmod Chmod
chmodFlag
        Link -> Doc ann
forall ann. Link -> Doc ann
prettyPrintLink Link
linkFlag
        CopySource -> Doc ann
forall ann. CopySource -> Doc ann
prettyPrintCopySource CopySource
sourceFlag
        NonEmpty SourcePath -> TargetPath -> Doc ann
forall ann. NonEmpty SourcePath -> TargetPath -> Doc ann
prettyPrintFileList NonEmpty SourcePath
sourcePaths TargetPath
targetPath
    Cmd Arguments Text
c -> do
      Doc ann
"CMD"
      Arguments Text -> Doc ann
forall ann. (?esc::Char) => Arguments Text -> Doc ann
prettyPrintArguments Arguments Text
c
    Label Pairs
l -> do
      Doc ann
"LABEL"
      Pairs -> Doc ann
forall ann. (?esc::Char) => Pairs -> Doc ann
prettyPrintPairs Pairs
l
    Env Pairs
ps -> do
      Doc ann
"ENV"
      Pairs -> Doc ann
forall ann. (?esc::Char) => Pairs -> Doc ann
prettyPrintPairs Pairs
ps
    User Text
u -> do
      Doc ann
"USER"
      Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
u
    Pragma PragmaDirective
p -> do
      Char -> Doc ann
forall ann. Char -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Char
'#'
      PragmaDirective -> Doc ann
forall ann. PragmaDirective -> Doc ann
prettyPrintPragma PragmaDirective
p
    Comment Text
s -> do
      Char -> Doc ann
forall ann. Char -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Char
'#'
      Text -> Doc ann
forall ann. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Text
s
    OnBuild Instruction Text
i' -> do
      Doc ann
"ONBUILD"
      Instruction Text -> Doc ann
forall ann. (?esc::Char) => Instruction Text -> Doc ann
prettyPrintInstruction Instruction Text
i'
    From BaseImage
b -> do
      Doc ann
"FROM"
      BaseImage -> Doc ann
forall ann. BaseImage -> Doc ann
prettyPrintBaseImage BaseImage
b
    Add
      AddArgs {NonEmpty SourcePath
sourcePaths :: NonEmpty SourcePath
$sel:sourcePaths:AddArgs :: AddArgs -> NonEmpty SourcePath
sourcePaths, TargetPath
targetPath :: TargetPath
$sel:targetPath:AddArgs :: AddArgs -> TargetPath
targetPath}
      AddFlags {Checksum
checksumFlag :: Checksum
$sel:checksumFlag:AddFlags :: AddFlags -> Checksum
checksumFlag, Chown
chownFlag :: Chown
$sel:chownFlag:AddFlags :: AddFlags -> Chown
chownFlag, Chmod
chmodFlag :: Chmod
$sel:chmodFlag:AddFlags :: AddFlags -> Chmod
chmodFlag, Link
linkFlag :: Link
$sel:linkFlag:AddFlags :: AddFlags -> Link
linkFlag} -> do
        Doc ann
"ADD"
        Checksum -> Doc ann
forall ann. Checksum -> Doc ann
prettyPrintChecksum Checksum
checksumFlag
        Chown -> Doc ann
forall ann. Chown -> Doc ann
prettyPrintChown Chown
chownFlag
        Chmod -> Doc ann
forall ann. Chmod -> Doc ann
prettyPrintChmod Chmod
chmodFlag
        Link -> Doc ann
forall ann. Link -> Doc ann
prettyPrintLink Link
linkFlag
        NonEmpty SourcePath -> TargetPath -> Doc ann
forall ann. NonEmpty SourcePath -> TargetPath -> Doc ann
prettyPrintFileList NonEmpty SourcePath
sourcePaths TargetPath
targetPath
    Shell Arguments Text
args -> do
      Doc ann
"SHELL"
      Arguments Text -> Doc ann
forall ann. (?esc::Char) => Arguments Text -> Doc ann
prettyPrintArguments Arguments Text
args
    Healthcheck Check Text
NoCheck -> Doc ann
"HEALTHCHECK NONE"
    Healthcheck (Check CheckArgs {Maybe Retries
Maybe Duration
Arguments Text
checkCommand :: Arguments Text
interval :: Maybe Duration
timeout :: Maybe Duration
startPeriod :: Maybe Duration
retries :: Maybe Retries
$sel:checkCommand:CheckArgs :: forall args. CheckArgs args -> Arguments args
$sel:interval:CheckArgs :: forall args. CheckArgs args -> Maybe Duration
$sel:timeout:CheckArgs :: forall args. CheckArgs args -> Maybe Duration
$sel:startPeriod:CheckArgs :: forall args. CheckArgs args -> Maybe Duration
$sel:retries:CheckArgs :: forall args. CheckArgs args -> Maybe Retries
..}) -> do
      Doc ann
"HEALTHCHECK"
      Text -> Maybe Duration -> Doc ann
forall ann. Text -> Maybe Duration -> Doc ann
prettyPrintDuration Text
"--interval=" Maybe Duration
interval
      Text -> Maybe Duration -> Doc ann
forall ann. Text -> Maybe Duration -> Doc ann
prettyPrintDuration Text
"--timeout=" Maybe Duration
timeout
      Text -> Maybe Duration -> Doc ann
forall ann. Text -> Maybe Duration -> Doc ann
prettyPrintDuration Text
"--start-period=" Maybe Duration
startPeriod
      Maybe Retries -> Doc ann
forall ann. Maybe Retries -> Doc ann
prettyPrintRetries Maybe Retries
retries
      Doc ann
"CMD"
      Arguments Text -> Doc ann
forall ann. (?esc::Char) => Arguments Text -> Doc ann
prettyPrintArguments Arguments Text
checkCommand
  where
    >> :: Doc ann -> Doc ann -> Doc ann
(>>) = Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
spaceCat

spaceCat :: Doc ann -> Doc ann -> Doc ann
spaceCat :: forall ann. Doc ann -> Doc ann -> Doc ann
spaceCat Doc ann
a Doc ann
Empty = Doc ann
a
spaceCat Doc ann
Empty Doc ann
b = Doc ann
b
spaceCat Doc ann
a Doc ann
b = Doc ann
a Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
b