{-# LANGUAGE NoImplicitPrelude #-}

module Stack.Options.DockerParser
  ( dockerOptsParser
  ) where

import           Data.List ( intercalate )
import qualified Data.Text as T
import           Distribution.Version ( anyVersion )
import           Options.Applicative
                   ( Parser, auto, completer, help, listCompleter, long, metavar
                   , option, str, value
                   )
import           Options.Applicative.Args ( argsOption )
import           Options.Applicative.Builder.Extra
                   ( dirCompleter, eitherReader', fileCompleter
                   , firstBoolFlagsFalse, firstBoolFlagsNoDefault
                   , firstBoolFlagsTrue, optionalFirst
                   )
import           Stack.Constants ( stackProgName )
import           Stack.Docker ( dockerCmdName )
import           Stack.Prelude
import           Stack.Options.Utils ( hideMods )
import           Stack.Types.Version ( IntersectingVersionRange (..) )
import           Stack.Types.Docker
                   ( DockerMonoidRepoOrImage (..), DockerOptsMonoid (..)
                   , dockerAutoPullArgName, dockerImageArgName
                   , dockerContainerNameArgName, dockerDetachArgName
                   , dockerEnvArgName, dockerPersistArgName
                   , dockerRegistryLoginArgName, dockerRegistryPasswordArgName
                   , dockerRegistryUsernameArgName, dockerRepoArgName
                   , dockerRunArgsArgName, dockerMountArgName
                   , dockerMountModeArgName, dockerNetworkArgName
                   , dockerSetUserArgName, dockerStackExeArgName
                   , dockerStackExeDownloadVal, dockerStackExeHostVal
                   , dockerStackExeImageVal, parseDockerStackExe
                   )

-- | Options parser configuration for Docker.

dockerOptsParser :: Bool -> Parser DockerOptsMonoid
dockerOptsParser :: Bool -> Parser DockerOptsMonoid
dockerOptsParser Bool
hide0 = Any
-> First Bool
-> First DockerMonoidRepoOrImage
-> First Bool
-> First String
-> First String
-> FirstTrue
-> FirstFalse
-> FirstFalse
-> First String
-> First String
-> [String]
-> [Mount]
-> First String
-> [String]
-> First DockerStackExe
-> First Bool
-> IntersectingVersionRange
-> DockerOptsMonoid
DockerOptsMonoid (Bool -> Any
Any Bool
False)
  (First Bool
 -> First DockerMonoidRepoOrImage
 -> First Bool
 -> First String
 -> First String
 -> FirstTrue
 -> FirstFalse
 -> FirstFalse
 -> First String
 -> First String
 -> [String]
 -> [Mount]
 -> First String
 -> [String]
 -> First DockerStackExe
 -> First Bool
 -> IntersectingVersionRange
 -> DockerOptsMonoid)
-> Parser (First Bool)
-> Parser
     (First DockerMonoidRepoOrImage
      -> First Bool
      -> First String
      -> First String
      -> FirstTrue
      -> FirstFalse
      -> FirstFalse
      -> First String
      -> First String
      -> [String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String
-> String -> Mod FlagFields (Maybe Bool) -> Parser (First Bool)
firstBoolFlagsNoDefault
        String
dockerCmdName
        String
"using a Docker container. --docker implies 'system-ghc: true'."
        Mod FlagFields (Maybe Bool)
forall {f :: * -> *} {a}. Mod f a
hide
  Parser
  (First DockerMonoidRepoOrImage
   -> First Bool
   -> First String
   -> First String
   -> FirstTrue
   -> FirstFalse
   -> FirstFalse
   -> First String
   -> First String
   -> [String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser (First DockerMonoidRepoOrImage)
-> Parser
     (First Bool
      -> First String
      -> First String
      -> FirstTrue
      -> FirstFalse
      -> FirstFalse
      -> First String
      -> First String
      -> [String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Maybe DockerMonoidRepoOrImage -> First DockerMonoidRepoOrImage)
-> Parser (Maybe DockerMonoidRepoOrImage)
-> Parser (First DockerMonoidRepoOrImage)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe DockerMonoidRepoOrImage -> First DockerMonoidRepoOrImage
forall a. Maybe a -> First a
First
        (   DockerMonoidRepoOrImage -> Maybe DockerMonoidRepoOrImage
forall a. a -> Maybe a
Just (DockerMonoidRepoOrImage -> Maybe DockerMonoidRepoOrImage)
-> (String -> DockerMonoidRepoOrImage)
-> String
-> Maybe DockerMonoidRepoOrImage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> DockerMonoidRepoOrImage
DockerMonoidRepo (String -> Maybe DockerMonoidRepoOrImage)
-> Parser String -> Parser (Maybe DockerMonoidRepoOrImage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM String -> Mod OptionFields String -> Parser String
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM String
forall s. IsString s => ReadM s
str
              (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerRepoArgName)
              Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall {f :: * -> *} {a}. Mod f a
hide
              Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"NAME"
              Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Docker repository name."
              )
        Parser (Maybe DockerMonoidRepoOrImage)
-> Parser (Maybe DockerMonoidRepoOrImage)
-> Parser (Maybe DockerMonoidRepoOrImage)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> DockerMonoidRepoOrImage -> Maybe DockerMonoidRepoOrImage
forall a. a -> Maybe a
Just (DockerMonoidRepoOrImage -> Maybe DockerMonoidRepoOrImage)
-> (String -> DockerMonoidRepoOrImage)
-> String
-> Maybe DockerMonoidRepoOrImage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> DockerMonoidRepoOrImage
DockerMonoidImage (String -> Maybe DockerMonoidRepoOrImage)
-> Parser String -> Parser (Maybe DockerMonoidRepoOrImage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM String -> Mod OptionFields String -> Parser String
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM String
forall s. IsString s => ReadM s
str
              (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerImageArgName)
              Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall {f :: * -> *} {a}. Mod f a
hide
              Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"IMAGE"
              Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Exact Docker image ID (overrides docker-repo)."
              )
        Parser (Maybe DockerMonoidRepoOrImage)
-> Parser (Maybe DockerMonoidRepoOrImage)
-> Parser (Maybe DockerMonoidRepoOrImage)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe DockerMonoidRepoOrImage
-> Parser (Maybe DockerMonoidRepoOrImage)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe DockerMonoidRepoOrImage
forall a. Maybe a
Nothing
        )
  Parser
  (First Bool
   -> First String
   -> First String
   -> FirstTrue
   -> FirstFalse
   -> FirstFalse
   -> First String
   -> First String
   -> [String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser (First Bool)
-> Parser
     (First String
      -> First String
      -> FirstTrue
      -> FirstFalse
      -> FirstFalse
      -> First String
      -> First String
      -> [String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String
-> String -> Mod FlagFields (Maybe Bool) -> Parser (First Bool)
firstBoolFlagsNoDefault
        (Text -> String
dockerOptName Text
dockerRegistryLoginArgName)
        String
"registry requires login."
        Mod FlagFields (Maybe Bool)
forall {f :: * -> *} {a}. Mod f a
hide
  Parser
  (First String
   -> First String
   -> FirstTrue
   -> FirstFalse
   -> FirstFalse
   -> First String
   -> First String
   -> [String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser (First String)
-> Parser
     (First String
      -> FirstTrue
      -> FirstFalse
      -> FirstFalse
      -> First String
      -> First String
      -> [String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod OptionFields String -> Parser (First String)
firstStrOption
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerRegistryUsernameArgName)
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall {f :: * -> *} {a}. Mod f a
hide
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"USERNAME"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Docker registry username."
        )
  Parser
  (First String
   -> FirstTrue
   -> FirstFalse
   -> FirstFalse
   -> First String
   -> First String
   -> [String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser (First String)
-> Parser
     (FirstTrue
      -> FirstFalse
      -> FirstFalse
      -> First String
      -> First String
      -> [String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod OptionFields String -> Parser (First String)
firstStrOption
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerRegistryPasswordArgName)
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall {f :: * -> *} {a}. Mod f a
hide
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"PASSWORD"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Docker registry password."
        )
  Parser
  (FirstTrue
   -> FirstFalse
   -> FirstFalse
   -> First String
   -> First String
   -> [String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser FirstTrue
-> Parser
     (FirstFalse
      -> FirstFalse
      -> First String
      -> First String
      -> [String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Mod FlagFields FirstTrue -> Parser FirstTrue
firstBoolFlagsTrue
        (Text -> String
dockerOptName Text
dockerAutoPullArgName)
        String
"automatic pulling latest version of image."
        Mod FlagFields FirstTrue
forall {f :: * -> *} {a}. Mod f a
hide
  Parser
  (FirstFalse
   -> FirstFalse
   -> First String
   -> First String
   -> [String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser FirstFalse
-> Parser
     (FirstFalse
      -> First String
      -> First String
      -> [String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Mod FlagFields FirstFalse -> Parser FirstFalse
firstBoolFlagsFalse
        (Text -> String
dockerOptName Text
dockerDetachArgName)
        String
"running a detached Docker container."
        Mod FlagFields FirstFalse
forall {f :: * -> *} {a}. Mod f a
hide
  Parser
  (FirstFalse
   -> First String
   -> First String
   -> [String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser FirstFalse
-> Parser
     (First String
      -> First String
      -> [String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Mod FlagFields FirstFalse -> Parser FirstFalse
firstBoolFlagsFalse
        (Text -> String
dockerOptName Text
dockerPersistArgName)
        String
"not deleting container after it exits."
        Mod FlagFields FirstFalse
forall {f :: * -> *} {a}. Mod f a
hide
  Parser
  (First String
   -> First String
   -> [String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser (First String)
-> Parser
     (First String
      -> [String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod OptionFields String -> Parser (First String)
firstStrOption
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerContainerNameArgName)
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall {f :: * -> *} {a}. Mod f a
hide
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"NAME"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Docker container name."
        )
  Parser
  (First String
   -> [String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser (First String)
-> Parser
     ([String]
      -> [Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod OptionFields String -> Parser (First String)
firstStrOption
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerNetworkArgName)
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall {f :: * -> *} {a}. Mod f a
hide
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"NETWORK"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Docker network."
        )
  Parser
  ([String]
   -> [Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser [String]
-> Parser
     ([Mount]
      -> First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod OptionFields [String] -> Parser [String]
argsOption
        (  String -> Mod OptionFields [String]
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerRunArgsArgName)
        Mod OptionFields [String]
-> Mod OptionFields [String] -> Mod OptionFields [String]
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields [String]
forall {f :: * -> *} {a}. Mod f a
hide
        Mod OptionFields [String]
-> Mod OptionFields [String] -> Mod OptionFields [String]
forall a. Semigroup a => a -> a -> a
<> [String] -> Mod OptionFields [String]
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value []
        Mod OptionFields [String]
-> Mod OptionFields [String] -> Mod OptionFields [String]
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields [String]
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"'ARG1 [ARG2 ...]'"
        Mod OptionFields [String]
-> Mod OptionFields [String] -> Mod OptionFields [String]
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields [String]
forall (f :: * -> *) a. String -> Mod f a
help String
"Additional options to pass to 'docker run'.")
  Parser
  ([Mount]
   -> First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser [Mount]
-> Parser
     (First String
      -> [String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Mount -> Parser [Mount]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (ReadM Mount -> Mod OptionFields Mount -> Parser Mount
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Mount
forall a. Read a => ReadM a
auto
        (  String -> Mod OptionFields Mount
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerMountArgName)
        Mod OptionFields Mount
-> Mod OptionFields Mount -> Mod OptionFields Mount
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields Mount
forall {f :: * -> *} {a}. Mod f a
hide
        Mod OptionFields Mount
-> Mod OptionFields Mount -> Mod OptionFields Mount
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Mount
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"(PATH | HOST-PATH:CONTAINER-PATH)"
        Mod OptionFields Mount
-> Mod OptionFields Mount -> Mod OptionFields Mount
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod OptionFields Mount
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer Completer
dirCompleter
        Mod OptionFields Mount
-> Mod OptionFields Mount -> Mod OptionFields Mount
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Mount
forall (f :: * -> *) a. String -> Mod f a
help String
"Mount volumes from host in container (can be specified \
                \multiple times)."
        ))
  Parser
  (First String
   -> [String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser (First String)
-> Parser
     ([String]
      -> First DockerStackExe
      -> First Bool
      -> IntersectingVersionRange
      -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod OptionFields String -> Parser (First String)
firstStrOption
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerMountModeArgName)
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall {f :: * -> *} {a}. Mod f a
hide
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"SUFFIX"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Volume mount mode suffix."
        )
  Parser
  ([String]
   -> First DockerStackExe
   -> First Bool
   -> IntersectingVersionRange
   -> DockerOptsMonoid)
-> Parser [String]
-> Parser
     (First DockerStackExe
      -> First Bool -> IntersectingVersionRange -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser [String]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (ReadM String -> Mod OptionFields String -> Parser String
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM String
forall s. IsString s => ReadM s
str
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerEnvArgName)
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields String
forall {f :: * -> *} {a}. Mod f a
hide
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"NAME=VALUE"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Set environment variable in container (can be specified \
                \multiple times)."
        ))
  Parser
  (First DockerStackExe
   -> First Bool -> IntersectingVersionRange -> DockerOptsMonoid)
-> Parser (First DockerStackExe)
-> Parser
     (First Bool -> IntersectingVersionRange -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser DockerStackExe -> Parser (First DockerStackExe)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (ReadM DockerStackExe
-> Mod OptionFields DockerStackExe -> Parser DockerStackExe
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ((String -> Either SomeException DockerStackExe)
-> ReadM DockerStackExe
forall e a. Show e => (String -> Either e a) -> ReadM a
eitherReader' String -> Either SomeException DockerStackExe
forall (m :: * -> *). MonadThrow m => String -> m DockerStackExe
parseDockerStackExe)
        ( let specialOpts :: [String]
specialOpts = [ String
dockerStackExeDownloadVal
                            , String
dockerStackExeHostVal
                            , String
dockerStackExeImageVal
                            ]
          in     String -> Mod OptionFields DockerStackExe
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
dockerOptName Text
dockerStackExeArgName)
              Mod OptionFields DockerStackExe
-> Mod OptionFields DockerStackExe
-> Mod OptionFields DockerStackExe
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields DockerStackExe
forall {f :: * -> *} {a}. Mod f a
hide
              Mod OptionFields DockerStackExe
-> Mod OptionFields DockerStackExe
-> Mod OptionFields DockerStackExe
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields DockerStackExe
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar (String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"|" ([String]
specialOpts [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String
"PATH"]))
              Mod OptionFields DockerStackExe
-> Mod OptionFields DockerStackExe
-> Mod OptionFields DockerStackExe
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod OptionFields DockerStackExe
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer ([String] -> Completer
listCompleter [String]
specialOpts Completer -> Completer -> Completer
forall a. Semigroup a => a -> a -> a
<> Completer
fileCompleter)
              Mod OptionFields DockerStackExe
-> Mod OptionFields DockerStackExe
-> Mod OptionFields DockerStackExe
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields DockerStackExe
forall (f :: * -> *) a. String -> Mod f a
help ( [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
                          [ String
"Location of "
                          , String
stackProgName
                          , String
" executable used in container."
                          ]
                      )
        ))
  Parser (First Bool -> IntersectingVersionRange -> DockerOptsMonoid)
-> Parser (First Bool)
-> Parser (IntersectingVersionRange -> DockerOptsMonoid)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String
-> String -> Mod FlagFields (Maybe Bool) -> Parser (First Bool)
firstBoolFlagsNoDefault
        (Text -> String
dockerOptName Text
dockerSetUserArgName)
        String
"setting user in container to match host."
        Mod FlagFields (Maybe Bool)
forall {f :: * -> *} {a}. Mod f a
hide
  Parser (IntersectingVersionRange -> DockerOptsMonoid)
-> Parser IntersectingVersionRange -> Parser DockerOptsMonoid
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IntersectingVersionRange -> Parser IntersectingVersionRange
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VersionRange -> IntersectingVersionRange
IntersectingVersionRange VersionRange
anyVersion)
 where
  dockerOptName :: Text -> String
dockerOptName Text
optName = String
dockerCmdName String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"-" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
optName
  firstStrOption :: Mod OptionFields String -> Parser (First String)
firstStrOption = Parser String -> Parser (First String)
forall (f :: * -> *) a. Alternative f => f a -> f (First a)
optionalFirst (Parser String -> Parser (First String))
-> (Mod OptionFields String -> Parser String)
-> Mod OptionFields String
-> Parser (First String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReadM String -> Mod OptionFields String -> Parser String
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM String
forall s. IsString s => ReadM s
str
  hide :: Mod f a
hide = Bool -> Mod f a
forall (f :: * -> *) a. Bool -> Mod f a
hideMods Bool
hide0