module Language.Docker.Parser.Copy
  ( parseCopy,
    parseAdd,
  )
where

import Data.List.NonEmpty (NonEmpty, fromList)
import qualified Data.Text as T
import Language.Docker.Parser.Prelude
import Language.Docker.Syntax

data Flag
  = FlagChecksum Checksum
  | FlagChown Chown
  | FlagChmod Chmod
  | FlagLink Link
  | FlagSource CopySource
  | FlagInvalid (Text, Text)

parseCopy :: (?esc :: Char) => Parser (Instruction Text)
parseCopy :: (?esc::Char) => Parser (Instruction Text)
parseCopy = do
  (?esc::Char) => Text -> Parser ()
Text -> Parser ()
reserved Text
"COPY"
  [Flag]
flags <- Parser Flag
(?esc::Char) => Parser Flag
copyFlag Parser Flag
-> Parser () -> ParsecT DockerfileError Text Identity [Flag]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepEndBy` Parser ()
(?esc::Char) => Parser ()
requiredWhitespace
  let chownFlags :: [Chown]
chownFlags = [Chown
c | FlagChown Chown
c <- [Flag]
flags]
  let chmodFlags :: [Chmod]
chmodFlags = [Chmod
c | FlagChmod Chmod
c <- [Flag]
flags]
  let linkFlags :: [Link]
linkFlags = [Link
l | FlagLink Link
l <- [Flag]
flags]
  let sourceFlags :: [CopySource]
sourceFlags = [CopySource
f | FlagSource CopySource
f <- [Flag]
flags]
  let invalid :: [(Text, Text)]
invalid = [(Text, Text)
i | FlagInvalid (Text, Text)
i <- [Flag]
flags]
  -- Let's do some validation on the flags
  case ([(Text, Text)]
invalid, [Chown]
chownFlags, [Chmod]
chmodFlags, [Link]
linkFlags, [CopySource]
sourceFlags) of
    ((Text
k, Text
v) : [(Text, Text)]
_, [Chown]
_, [Chmod]
_, [Link]
_, [CopySource]
_) -> Text -> Text -> Parser (Instruction Text)
forall a. Text -> Text -> Parser a
unexpectedFlag Text
k Text
v
    ([(Text, Text)]
_, Chown
_ : Chown
_ : [Chown]
_, [Chmod]
_, [Link]
_, [CopySource]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--chown"
    ([(Text, Text)]
_, [Chown]
_, Chmod
_ : Chmod
_ : [Chmod]
_, [Link]
_, [CopySource]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--chmod"
    ([(Text, Text)]
_, [Chown]
_, [Chmod]
_, Link
_ : Link
_ : [Link]
_, [CopySource]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--link"
    ([(Text, Text)]
_, [Chown]
_, [Chmod]
_, [Link]
_, CopySource
_ : CopySource
_ : [CopySource]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--from"
    ([(Text, Text)], [Chown], [Chmod], [Link], [CopySource])
_ -> do
      let cho :: Chown
cho =
            case [Chown]
chownFlags of
              [] -> Chown
NoChown
              Chown
c : [Chown]
_ -> Chown
c
      let chm :: Chmod
chm =
            case [Chmod]
chmodFlags of
              [] -> Chmod
NoChmod
              Chmod
c : [Chmod]
_ -> Chmod
c
      let lnk :: Link
lnk =
            case [Link]
linkFlags of
              [] -> Link
NoLink
              Link
l : [Link]
_ -> Link
l
      let fr :: CopySource
fr =
            case [CopySource]
sourceFlags of
              [] -> CopySource
NoSource
              CopySource
f : [CopySource]
_ -> CopySource
f
      Parser (Instruction Text) -> Parser (Instruction Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ((?esc::Char) =>
(NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
(NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
heredocList (\NonEmpty SourcePath
src TargetPath
dest -> CopyArgs -> CopyFlags -> Instruction Text
forall args. CopyArgs -> CopyFlags -> Instruction args
Copy (NonEmpty SourcePath -> TargetPath -> CopyArgs
CopyArgs NonEmpty SourcePath
src TargetPath
dest) (Chown -> Chmod -> Link -> CopySource -> CopyFlags
CopyFlags Chown
cho Chmod
chm Link
lnk CopySource
fr)))
        Parser (Instruction Text)
-> Parser (Instruction Text) -> Parser (Instruction Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (?esc::Char) =>
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
fileList Text
"COPY" (\NonEmpty SourcePath
src TargetPath
dest -> CopyArgs -> CopyFlags -> Instruction Text
forall args. CopyArgs -> CopyFlags -> Instruction args
Copy (NonEmpty SourcePath -> TargetPath -> CopyArgs
CopyArgs NonEmpty SourcePath
src TargetPath
dest) (Chown -> Chmod -> Link -> CopySource -> CopyFlags
CopyFlags Chown
cho Chmod
chm Link
lnk CopySource
fr))

parseAdd :: (?esc :: Char) => Parser (Instruction Text)
parseAdd :: (?esc::Char) => Parser (Instruction Text)
parseAdd = do
  (?esc::Char) => Text -> Parser ()
Text -> Parser ()
reserved Text
"ADD"
  [Flag]
flags <- Parser Flag
(?esc::Char) => Parser Flag
addFlag Parser Flag
-> Parser () -> ParsecT DockerfileError Text Identity [Flag]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepEndBy` Parser ()
(?esc::Char) => Parser ()
requiredWhitespace
  let checksumFlags :: [Checksum]
checksumFlags = [Checksum
c | FlagChecksum Checksum
c <- [Flag]
flags]
  let chownFlags :: [Chown]
chownFlags = [Chown
c | FlagChown Chown
c <- [Flag]
flags]
  let chmodFlags :: [Chmod]
chmodFlags = [Chmod
c | FlagChmod Chmod
c <- [Flag]
flags]
  let linkFlags :: [Link]
linkFlags = [Link
l | FlagLink Link
l <- [Flag]
flags]
  let invalidFlags :: [(Text, Text)]
invalidFlags = [(Text, Text)
i | FlagInvalid (Text, Text)
i <- [Flag]
flags]
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a. ParsecT DockerfileError Text Identity a -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--") Parser () -> String -> Parser ()
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?>
    String
"only the --checksum, --chown, --chmod, --link flags or the src and dest paths"
  case ([(Text, Text)]
invalidFlags, [Checksum]
checksumFlags, [Chown]
chownFlags, [Link]
linkFlags, [Chmod]
chmodFlags) of
    ((Text
k, Text
v) : [(Text, Text)]
_, [Checksum]
_, [Chown]
_, [Link]
_, [Chmod]
_) -> Text -> Text -> Parser (Instruction Text)
forall a. Text -> Text -> Parser a
unexpectedFlag Text
k Text
v
    ([(Text, Text)]
_, Checksum
_ : Checksum
_ : [Checksum]
_, [Chown]
_, [Link]
_, [Chmod]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--checksum"
    ([(Text, Text)]
_, [Checksum]
_, Chown
_ : Chown
_ : [Chown]
_, [Link]
_, [Chmod]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--chown"
    ([(Text, Text)]
_, [Checksum]
_, [Chown]
_, Link
_ : Link
_ : [Link]
_, [Chmod]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--chmod"
    ([(Text, Text)]
_, [Checksum]
_, [Chown]
_, [Link]
_, Chmod
_ : Chmod
_ : [Chmod]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--link"
    ([(Text, Text)], [Checksum], [Chown], [Link], [Chmod])
_ -> do
      let chk :: Checksum
chk = case [Checksum]
checksumFlags of
                  [] -> Checksum
NoChecksum
                  Checksum
c : [Checksum]
_ -> Checksum
c
      let cho :: Chown
cho = case [Chown]
chownFlags of
                  [] -> Chown
NoChown
                  Chown
c : [Chown]
_ -> Chown
c
      let chm :: Chmod
chm = case [Chmod]
chmodFlags of
                  [] -> Chmod
NoChmod
                  Chmod
c : [Chmod]
_ -> Chmod
c
      let lnk :: Link
lnk =
            case [Link]
linkFlags of
              [] -> Link
NoLink
              Link
l : [Link]
_ -> Link
l
      (?esc::Char) =>
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
fileList Text
"ADD" (\NonEmpty SourcePath
src TargetPath
dest -> AddArgs -> AddFlags -> Instruction Text
forall args. AddArgs -> AddFlags -> Instruction args
Add (NonEmpty SourcePath -> TargetPath -> AddArgs
AddArgs NonEmpty SourcePath
src TargetPath
dest) (Checksum -> Chown -> Chmod -> Link -> AddFlags
AddFlags Checksum
chk Chown
cho Chmod
chm Link
lnk))

heredocList :: (?esc :: Char) =>
               (NonEmpty SourcePath -> TargetPath -> Instruction Text) ->
               Parser (Instruction Text)
heredocList :: (?esc::Char) =>
(NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
heredocList NonEmpty SourcePath -> TargetPath -> Instruction Text
constr = do
  [Text]
markers <- ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser Text -> ParsecT DockerfileError Text Identity [Text]
forall a. Parser a -> Parser [a]
spaceSep1 Parser Text
(?esc::Char) => Parser Text
heredocMarker) ParsecT DockerfileError Text Identity [Text]
-> String -> ParsecT DockerfileError Text Identity [Text]
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"a list of heredoc markers"
  Text
target <- (?esc::Char) => String -> Parser Text
String -> Parser Text
untilEol String
"target path"
  case [Text] -> [Text]
forall a. [a] -> [a]
reverse [Text]
markers of
    [] -> DockerfileError -> Parser ()
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser ()) -> DockerfileError -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
FileListError String
"empty list of heredoc markers"
    Text
m:[Text]
_ -> Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Text -> Parser ()) -> Parser Text -> Parser ()
forall a b. (a -> b) -> a -> b
$ Text -> Parser Text
heredocContent Text
m
  Instruction Text -> Parser (Instruction Text)
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction Text -> Parser (Instruction Text))
-> Instruction Text -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ NonEmpty SourcePath -> TargetPath -> Instruction Text
constr (Text -> SourcePath
SourcePath (Text -> SourcePath) -> NonEmpty Text -> NonEmpty SourcePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text] -> NonEmpty Text
forall a. HasCallStack => [a] -> NonEmpty a
fromList [Text]
markers) (Text -> TargetPath
TargetPath Text
target)

fileList :: (?esc :: Char) => Text ->
            (NonEmpty SourcePath -> TargetPath -> Instruction Text) ->
            Parser (Instruction Text)
fileList :: (?esc::Char) =>
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
fileList Text
name NonEmpty SourcePath -> TargetPath -> Instruction Text
constr = do
  [Text]
paths <-
    (ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity [Text]
stringList ParsecT DockerfileError Text Identity [Text]
-> String -> ParsecT DockerfileError Text Identity [Text]
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"an array of strings [\"src_file\", \"dest_file\"]")
      ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity [Text]
spaceSeparated ParsecT DockerfileError Text Identity [Text]
-> String -> ParsecT DockerfileError Text Identity [Text]
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"a space separated list of file paths")
  case [Text]
paths of
    [Text
_] -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
FileListError (Text -> String
T.unpack Text
name)
    [Text]
_ -> Instruction Text -> Parser (Instruction Text)
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction Text -> Parser (Instruction Text))
-> Instruction Text -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ NonEmpty SourcePath -> TargetPath -> Instruction Text
constr (Text -> SourcePath
SourcePath (Text -> SourcePath) -> NonEmpty Text -> NonEmpty SourcePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text] -> NonEmpty Text
forall a. HasCallStack => [a] -> NonEmpty a
fromList ([Text] -> [Text]
forall a. HasCallStack => [a] -> [a]
init [Text]
paths)) (Text -> TargetPath
TargetPath (Text -> TargetPath) -> Text -> TargetPath
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. HasCallStack => [a] -> a
last [Text]
paths)
  where
    spaceSeparated :: ParsecT DockerfileError Text Identity [Text]
spaceSeparated =
      (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"a file" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ') Parser Text
-> Parser () -> ParsecT DockerfileError Text Identity [Text]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepEndBy1` (Parser () -> Parser ()
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parser ()
(?esc::Char) => Parser ()
requiredWhitespace Parser () -> String -> Parser ()
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"at least another file path")
    stringList :: ParsecT DockerfileError Text Identity [Text]
stringList = ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a. (?esc::Char) => Parser a -> Parser a
brackets (ParsecT DockerfileError Text Identity [Text]
 -> ParsecT DockerfileError Text Identity [Text])
-> ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a b. (a -> b) -> a -> b
$ Parser Text -> ParsecT DockerfileError Text Identity [Text]
forall a. (?esc::Char) => Parser a -> Parser [a]
commaSep Parser Text
doubleQuotedString

unexpectedFlag :: Text -> Text -> Parser a
unexpectedFlag :: forall a. Text -> Text -> Parser a
unexpectedFlag Text
name Text
"" = DockerfileError -> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => e -> m a
customFailure (DockerfileError -> ParsecT DockerfileError Text Identity a)
-> DockerfileError -> ParsecT DockerfileError Text Identity a
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
NoValueFlagError (Text -> String
T.unpack Text
name)
unexpectedFlag Text
name Text
_ = DockerfileError -> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => e -> m a
customFailure (DockerfileError -> ParsecT DockerfileError Text Identity a)
-> DockerfileError -> ParsecT DockerfileError Text Identity a
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
InvalidFlagError (Text -> String
T.unpack Text
name)

copyFlag :: (?esc :: Char) => Parser Flag
copyFlag :: (?esc::Char) => Parser Flag
copyFlag = (CopySource -> Flag
FlagSource (CopySource -> Flag)
-> ParsecT DockerfileError Text Identity CopySource -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity CopySource
-> ParsecT DockerfileError Text Identity CopySource
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity CopySource
(?esc::Char) => ParsecT DockerfileError Text Identity CopySource
copySource Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"only one --from") Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Flag
(?esc::Char) => Parser Flag
addFlag

addFlag :: (?esc :: Char) => Parser Flag
addFlag :: (?esc::Char) => Parser Flag
addFlag = (Checksum -> Flag
FlagChecksum (Checksum -> Flag)
-> ParsecT DockerfileError Text Identity Checksum -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Checksum
-> ParsecT DockerfileError Text Identity Checksum
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Checksum
(?esc::Char) => ParsecT DockerfileError Text Identity Checksum
checksum Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--checksum")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Chown -> Flag
FlagChown (Chown -> Flag)
-> ParsecT DockerfileError Text Identity Chown -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Chown
-> ParsecT DockerfileError Text Identity Chown
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Chown
(?esc::Char) => ParsecT DockerfileError Text Identity Chown
chown Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--chown")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Chmod -> Flag
FlagChmod (Chmod -> Flag)
-> ParsecT DockerfileError Text Identity Chmod -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Chmod
-> ParsecT DockerfileError Text Identity Chmod
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Chmod
(?esc::Char) => ParsecT DockerfileError Text Identity Chmod
chmod Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--chmod")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Link -> Flag
FlagLink (Link -> Flag)
-> ParsecT DockerfileError Text Identity Link -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Link
-> ParsecT DockerfileError Text Identity Link
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Link
link Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--link")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ((Text, Text) -> Flag
FlagInvalid ((Text, Text) -> Flag)
-> ParsecT DockerfileError Text Identity (Text, Text)
-> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity (Text, Text)
-> ParsecT DockerfileError Text Identity (Text, Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity (Text, Text)
(?esc::Char) => ParsecT DockerfileError Text Identity (Text, Text)
anyFlag Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"other flag")

checksum :: (?esc :: Char) => Parser Checksum
checksum :: (?esc::Char) => ParsecT DockerfileError Text Identity Checksum
checksum = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--checksum="
  Text
chk <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the remote file checksum" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
  Checksum -> ParsecT DockerfileError Text Identity Checksum
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Checksum -> ParsecT DockerfileError Text Identity Checksum)
-> Checksum -> ParsecT DockerfileError Text Identity Checksum
forall a b. (a -> b) -> a -> b
$ Text -> Checksum
Checksum Text
chk

chown :: (?esc :: Char) => Parser Chown
chown :: (?esc::Char) => ParsecT DockerfileError Text Identity Chown
chown = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--chown="
  Text
cho <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the user and group for chown" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
  Chown -> ParsecT DockerfileError Text Identity Chown
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Chown -> ParsecT DockerfileError Text Identity Chown)
-> Chown -> ParsecT DockerfileError Text Identity Chown
forall a b. (a -> b) -> a -> b
$ Text -> Chown
Chown Text
cho

chmod :: (?esc :: Char) => Parser Chmod
chmod :: (?esc::Char) => ParsecT DockerfileError Text Identity Chmod
chmod = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--chmod="
  Text
chm <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the mode for chmod" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
  Chmod -> ParsecT DockerfileError Text Identity Chmod
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Chmod -> ParsecT DockerfileError Text Identity Chmod)
-> Chmod -> ParsecT DockerfileError Text Identity Chmod
forall a b. (a -> b) -> a -> b
$ Text -> Chmod
Chmod Text
chm

link :: Parser Link
link :: ParsecT DockerfileError Text Identity Link
link = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--link"
  Link -> ParsecT DockerfileError Text Identity Link
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return Link
Link

copySource :: (?esc :: Char) => Parser CopySource
copySource :: (?esc::Char) => ParsecT DockerfileError Text Identity CopySource
copySource = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--from="
  Text
src <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the copy source path" Char -> Bool
isNl
  CopySource -> ParsecT DockerfileError Text Identity CopySource
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (CopySource -> ParsecT DockerfileError Text Identity CopySource)
-> CopySource -> ParsecT DockerfileError Text Identity CopySource
forall a b. (a -> b) -> a -> b
$ Text -> CopySource
CopySource Text
src

anyFlag :: (?esc :: Char) => Parser (Text, Text)
anyFlag :: (?esc::Char) => ParsecT DockerfileError Text Identity (Text, Text)
anyFlag = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--"
  Text
name <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the flag value" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'=')
  ParsecT DockerfileError Text Identity Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity Char -> Parser ())
-> ParsecT DockerfileError Text Identity Char -> Parser ()
forall a b. (a -> b) -> a -> b
$ Token Text -> ParsecT DockerfileError Text Identity (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'='
  Text
val <- (?esc::Char) => (Char -> Bool) -> Parser Text
(Char -> Bool) -> Parser Text
anyUnless (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
  (Text, Text) -> ParsecT DockerfileError Text Identity (Text, Text)
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Text -> Text
T.append Text
"--" Text
name, Text
val)