{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}

module Control.Process.CreateProcess
  ( CreateProcess,
    GetCreateProcess (..),
    HasCreateProcess (..),
    ReviewCreateProcess (..),
    AsCreateProcess (..),
    streams,
    streams1,
  )
where

import Control.Applicative (Applicative ((<*>)))
import Control.Category (id, (.))
import Control.Lens
  ( Field1 (_1),
    Field2 (_2),
    Getter,
    Lens',
    Prism',
    Review,
    Traversable (traverse),
    Traversal',
    Traversal1',
    only,
    unto,
    _Just,
  )
import Control.Process.UserID (HasUserID (userIDWord32))
import Data.Bool (Bool (True))
import Data.Functor (Functor (fmap), (<$>))
import Data.Functor.Apply (Apply ((<.>)))
import Data.Maybe (Maybe (..))
import Data.String (String)
import Data.Word (Word32)
import System.FilePath (FilePath)
import System.Process (CreateProcess, StdStream (..))
import qualified System.Process as Process (CreateProcess (..))
import System.Process.Internals (GroupID, UserID)

-- $setup
-- >>> import Prelude
-- >>> import Control.Lens
-- >>> import System.Process (proc, shell)

-- | Type class for values that can be viewed as a @CreateProcess@.
--
-- >>> view getCreateProcess (proc "echo" ["hello"]) == proc "echo" ["hello"]
-- True
class GetCreateProcess a where
  getCreateProcess ::
    Getter a CreateProcess

-- |
--
-- >>> view getCreateProcess (proc "echo" ["hello"]) == proc "echo" ["hello"]
-- True
instance GetCreateProcess CreateProcess where
  getCreateProcess :: Getter CreateProcess CreateProcess
getCreateProcess = (CreateProcess -> f CreateProcess)
-> CreateProcess -> f CreateProcess
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
  {-# INLINE getCreateProcess #-}

-- | Type class for values with a lens into a @CreateProcess@.
--
-- >>> view close_fds (proc "echo" ["hello"])
-- False
class (GetCreateProcess a) => HasCreateProcess a where
  create_process ::
    Lens' a CreateProcess
  {-# INLINE child_group #-}
  child_group ::
    Lens' a (Maybe GroupID)
  child_group =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Maybe GroupID -> f (Maybe GroupID))
    -> CreateProcess -> f CreateProcess)
-> (Maybe GroupID -> f (Maybe GroupID))
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Maybe GroupID -> f (Maybe GroupID))
-> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a (Maybe GroupID)
Lens' CreateProcess (Maybe GroupID)
child_group
  {-# INLINE child_user #-}
  child_user ::
    Lens' a (Maybe UserID)
  child_user =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Maybe UserID -> f (Maybe UserID))
    -> CreateProcess -> f CreateProcess)
-> (Maybe UserID -> f (Maybe UserID))
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Maybe UserID -> f (Maybe UserID))
-> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a (Maybe UserID)
Lens' CreateProcess (Maybe UserID)
child_user
  {-# INLINE close_fds #-}
  close_fds ::
    Lens' a Bool
  close_fds =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Bool -> f Bool) -> CreateProcess -> f CreateProcess)
-> (Bool -> f Bool)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Bool -> f Bool) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a Bool
Lens' CreateProcess Bool
close_fds
  {-# INLINE create_group #-}
  create_group ::
    Lens' a Bool
  create_group =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Bool -> f Bool) -> CreateProcess -> f CreateProcess)
-> (Bool -> f Bool)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Bool -> f Bool) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a Bool
Lens' CreateProcess Bool
create_group
  {-# INLINE create_new_console #-}
  create_new_console ::
    Lens' a Bool
  create_new_console =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Bool -> f Bool) -> CreateProcess -> f CreateProcess)
-> (Bool -> f Bool)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Bool -> f Bool) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a Bool
Lens' CreateProcess Bool
create_new_console
  {-# INLINE cwd #-}
  cwd ::
    Lens' a (Maybe FilePath)
  cwd =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Maybe FilePath -> f (Maybe FilePath))
    -> CreateProcess -> f CreateProcess)
-> (Maybe FilePath -> f (Maybe FilePath))
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Maybe FilePath -> f (Maybe FilePath))
-> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a (Maybe FilePath)
Lens' CreateProcess (Maybe FilePath)
cwd
  {-# INLINE delegate_ctlc #-}
  delegate_ctlc ::
    Lens' a Bool
  delegate_ctlc =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Bool -> f Bool) -> CreateProcess -> f CreateProcess)
-> (Bool -> f Bool)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Bool -> f Bool) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a Bool
Lens' CreateProcess Bool
delegate_ctlc
  {-# INLINE detach_console #-}
  detach_console ::
    Lens' a Bool
  detach_console =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Bool -> f Bool) -> CreateProcess -> f CreateProcess)
-> (Bool -> f Bool)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Bool -> f Bool) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a Bool
Lens' CreateProcess Bool
detach_console
  {-# INLINE env #-}
  env ::
    Lens' a (Maybe [(String, String)])
  env =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Maybe [(FilePath, FilePath)]
     -> f (Maybe [(FilePath, FilePath)]))
    -> CreateProcess -> f CreateProcess)
-> (Maybe [(FilePath, FilePath)]
    -> f (Maybe [(FilePath, FilePath)]))
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Maybe [(FilePath, FilePath)] -> f (Maybe [(FilePath, FilePath)]))
-> CreateProcess -> f CreateProcess
forall a.
HasCreateProcess a =>
Lens' a (Maybe [(FilePath, FilePath)])
Lens' CreateProcess (Maybe [(FilePath, FilePath)])
env
  {-# INLINE new_session #-}
  new_session ::
    Lens' a Bool
  new_session =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Bool -> f Bool) -> CreateProcess -> f CreateProcess)
-> (Bool -> f Bool)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Bool -> f Bool) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a Bool
Lens' CreateProcess Bool
new_session
  {-# INLINE std_err #-}
  std_err ::
    Lens' a StdStream
  std_err =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((StdStream -> f StdStream) -> CreateProcess -> f CreateProcess)
-> (StdStream -> f StdStream)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (StdStream -> f StdStream) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a StdStream
Lens' CreateProcess StdStream
std_err
  {-# INLINE std_in #-}
  std_in ::
    Lens' a StdStream
  std_in =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((StdStream -> f StdStream) -> CreateProcess -> f CreateProcess)
-> (StdStream -> f StdStream)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (StdStream -> f StdStream) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a StdStream
Lens' CreateProcess StdStream
std_in
  {-# INLINE std_out #-}
  std_out ::
    Lens' a StdStream
  std_out =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((StdStream -> f StdStream) -> CreateProcess -> f CreateProcess)
-> (StdStream -> f StdStream)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (StdStream -> f StdStream) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a StdStream
Lens' CreateProcess StdStream
std_out
  {-# INLINE use_process_jobs #-}
  use_process_jobs ::
    Lens' a Bool
  use_process_jobs =
    (CreateProcess -> f CreateProcess) -> a -> f a
forall a. HasCreateProcess a => Lens' a CreateProcess
Lens' a CreateProcess
create_process ((CreateProcess -> f CreateProcess) -> a -> f a)
-> ((Bool -> f Bool) -> CreateProcess -> f CreateProcess)
-> (Bool -> f Bool)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Bool -> f Bool) -> CreateProcess -> f CreateProcess
forall a. HasCreateProcess a => Lens' a Bool
Lens' CreateProcess Bool
use_process_jobs

  {-# INLINE cwd' #-}
  cwd' ::
    Traversal' a FilePath
  cwd' =
    (Maybe FilePath -> f (Maybe FilePath)) -> a -> f a
forall a. HasCreateProcess a => Lens' a (Maybe FilePath)
Lens' a (Maybe FilePath)
cwd ((Maybe FilePath -> f (Maybe FilePath)) -> a -> f a)
-> ((FilePath -> f FilePath)
    -> Maybe FilePath -> f (Maybe FilePath))
-> (FilePath -> f FilePath)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (FilePath -> f FilePath) -> Maybe FilePath -> f (Maybe FilePath)
forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p (Maybe a) (f (Maybe b))
_Just
  {-# INLINE envList #-}
  envList ::
    Traversal' a [(String, String)]
  envList =
    (Maybe [(FilePath, FilePath)] -> f (Maybe [(FilePath, FilePath)]))
-> a -> f a
forall a.
HasCreateProcess a =>
Lens' a (Maybe [(FilePath, FilePath)])
Lens' a (Maybe [(FilePath, FilePath)])
env ((Maybe [(FilePath, FilePath)] -> f (Maybe [(FilePath, FilePath)]))
 -> a -> f a)
-> (([(FilePath, FilePath)] -> f [(FilePath, FilePath)])
    -> Maybe [(FilePath, FilePath)]
    -> f (Maybe [(FilePath, FilePath)]))
-> ([(FilePath, FilePath)] -> f [(FilePath, FilePath)])
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ([(FilePath, FilePath)] -> f [(FilePath, FilePath)])
-> Maybe [(FilePath, FilePath)] -> f (Maybe [(FilePath, FilePath)])
forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p (Maybe a) (f (Maybe b))
_Just
  {-# INLINE envElement #-}
  envElement ::
    Traversal' a (String, String)
  envElement =
    ([(FilePath, FilePath)] -> f [(FilePath, FilePath)]) -> a -> f a
forall a. HasCreateProcess a => Traversal' a [(FilePath, FilePath)]
Traversal' a [(FilePath, FilePath)]
envList (([(FilePath, FilePath)] -> f [(FilePath, FilePath)]) -> a -> f a)
-> (((FilePath, FilePath) -> f (FilePath, FilePath))
    -> [(FilePath, FilePath)] -> f [(FilePath, FilePath)])
-> ((FilePath, FilePath) -> f (FilePath, FilePath))
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ((FilePath, FilePath) -> f (FilePath, FilePath))
-> [(FilePath, FilePath)] -> f [(FilePath, FilePath)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse
  {-# INLINE envElementKey #-}
  envElementKey ::
    Traversal' a String
  envElementKey =
    ((FilePath, FilePath) -> f (FilePath, FilePath)) -> a -> f a
forall a. HasCreateProcess a => Traversal' a (FilePath, FilePath)
Traversal' a (FilePath, FilePath)
envElement (((FilePath, FilePath) -> f (FilePath, FilePath)) -> a -> f a)
-> ((FilePath -> f FilePath)
    -> (FilePath, FilePath) -> f (FilePath, FilePath))
-> (FilePath -> f FilePath)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (FilePath -> f FilePath)
-> (FilePath, FilePath) -> f (FilePath, FilePath)
forall s t a b. Field1 s t a b => Lens s t a b
Lens (FilePath, FilePath) (FilePath, FilePath) FilePath FilePath
_1
  {-# INLINE envElementValue #-}
  envElementValue ::
    Traversal' a String
  envElementValue =
    ((FilePath, FilePath) -> f (FilePath, FilePath)) -> a -> f a
forall a. HasCreateProcess a => Traversal' a (FilePath, FilePath)
Traversal' a (FilePath, FilePath)
envElement (((FilePath, FilePath) -> f (FilePath, FilePath)) -> a -> f a)
-> ((FilePath -> f FilePath)
    -> (FilePath, FilePath) -> f (FilePath, FilePath))
-> (FilePath -> f FilePath)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (FilePath -> f FilePath)
-> (FilePath, FilePath) -> f (FilePath, FilePath)
forall s t a b. Field2 s t a b => Lens s t a b
Lens (FilePath, FilePath) (FilePath, FilePath) FilePath FilePath
_2
  {-# INLINE close_fds' #-}
  close_fds' ::
    Traversal' a ()
  close_fds' =
    (Bool -> f Bool) -> a -> f a
forall a. HasCreateProcess a => Lens' a Bool
Lens' a Bool
close_fds ((Bool -> f Bool) -> a -> f a)
-> ((() -> f ()) -> Bool -> f Bool) -> (() -> f ()) -> a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Prism' Bool ()
forall a. Eq a => a -> Prism' a ()
only Bool
True
  {-# INLINE create_group' #-}
  create_group' ::
    Traversal' a ()
  create_group' =
    (Bool -> f Bool) -> a -> f a
forall a. HasCreateProcess a => Lens' a Bool
Lens' a Bool
create_group ((Bool -> f Bool) -> a -> f a)
-> ((() -> f ()) -> Bool -> f Bool) -> (() -> f ()) -> a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Prism' Bool ()
forall a. Eq a => a -> Prism' a ()
only Bool
True
  {-# INLINE delegate_ctlc' #-}
  delegate_ctlc' ::
    Traversal' a ()
  delegate_ctlc' =
    (Bool -> f Bool) -> a -> f a
forall a. HasCreateProcess a => Lens' a Bool
Lens' a Bool
delegate_ctlc ((Bool -> f Bool) -> a -> f a)
-> ((() -> f ()) -> Bool -> f Bool) -> (() -> f ()) -> a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Prism' Bool ()
forall a. Eq a => a -> Prism' a ()
only Bool
True
  {-# INLINE detach_console' #-}
  detach_console' ::
    Traversal' a ()
  detach_console' =
    (Bool -> f Bool) -> a -> f a
forall a. HasCreateProcess a => Lens' a Bool
Lens' a Bool
detach_console ((Bool -> f Bool) -> a -> f a)
-> ((() -> f ()) -> Bool -> f Bool) -> (() -> f ()) -> a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Prism' Bool ()
forall a. Eq a => a -> Prism' a ()
only Bool
True
  {-# INLINE create_new_console' #-}
  create_new_console' ::
    Traversal' a ()
  create_new_console' =
    (Bool -> f Bool) -> a -> f a
forall a. HasCreateProcess a => Lens' a Bool
Lens' a Bool
create_new_console ((Bool -> f Bool) -> a -> f a)
-> ((() -> f ()) -> Bool -> f Bool) -> (() -> f ()) -> a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Prism' Bool ()
forall a. Eq a => a -> Prism' a ()
only Bool
True
  {-# INLINE new_session' #-}
  new_session' ::
    Traversal' a ()
  new_session' =
    (Bool -> f Bool) -> a -> f a
forall a. HasCreateProcess a => Lens' a Bool
Lens' a Bool
new_session ((Bool -> f Bool) -> a -> f a)
-> ((() -> f ()) -> Bool -> f Bool) -> (() -> f ()) -> a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Prism' Bool ()
forall a. Eq a => a -> Prism' a ()
only Bool
True
  {-# INLINE child_group' #-}
  child_group' ::
    Traversal' a GroupID
  child_group' =
    (Maybe GroupID -> f (Maybe GroupID)) -> a -> f a
forall a. HasCreateProcess a => Lens' a (Maybe GroupID)
Lens' a (Maybe GroupID)
child_group ((Maybe GroupID -> f (Maybe GroupID)) -> a -> f a)
-> ((GroupID -> f GroupID) -> Maybe GroupID -> f (Maybe GroupID))
-> (GroupID -> f GroupID)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (GroupID -> f GroupID) -> Maybe GroupID -> f (Maybe GroupID)
forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p (Maybe a) (f (Maybe b))
_Just
  {-# INLINE child_user' #-}
  child_user' ::
    Traversal' a UserID
  child_user' =
    (Maybe UserID -> f (Maybe UserID)) -> a -> f a
forall a. HasCreateProcess a => Lens' a (Maybe UserID)
Lens' a (Maybe UserID)
child_user ((Maybe UserID -> f (Maybe UserID)) -> a -> f a)
-> ((UserID -> f UserID) -> Maybe UserID -> f (Maybe UserID))
-> (UserID -> f UserID)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (UserID -> f UserID) -> Maybe UserID -> f (Maybe UserID)
forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p (Maybe a) (f (Maybe b))
_Just
  {-# INLINE child_user'' #-}
  child_user'' ::
    Traversal' a Word32
  child_user'' =
    (UserID -> f UserID) -> a -> f a
forall a. HasCreateProcess a => Traversal' a UserID
Traversal' a UserID
child_user' ((UserID -> f UserID) -> a -> f a)
-> ((Word32 -> f Word32) -> UserID -> f UserID)
-> (Word32 -> f Word32)
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Word32 -> f Word32) -> UserID -> f UserID
forall a. HasUserID a => Lens' a Word32
Lens' UserID Word32
userIDWord32
  {-# INLINE use_process_jobs' #-}
  use_process_jobs' ::
    Traversal' a ()
  use_process_jobs' =
    (Bool -> f Bool) -> a -> f a
forall a. HasCreateProcess a => Lens' a Bool
Lens' a Bool
use_process_jobs ((Bool -> f Bool) -> a -> f a)
-> ((() -> f ()) -> Bool -> f Bool) -> (() -> f ()) -> a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Prism' Bool ()
forall a. Eq a => a -> Prism' a ()
only Bool
True

-- |
--
-- >>> view close_fds (proc "echo" ["hello"])
-- False
-- >>> view (std_in) (proc "echo" ["hello"])
-- Inherit
-- >>> view cwd (proc "echo" ["hello"])
-- Nothing
instance HasCreateProcess CreateProcess where
  create_process :: Lens' CreateProcess CreateProcess
create_process =
    (CreateProcess -> f CreateProcess)
-> CreateProcess -> f CreateProcess
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
  child_group :: Lens' CreateProcess (Maybe GroupID)
child_group Maybe GroupID -> f (Maybe GroupID)
f CreateProcess
p =
    (Maybe GroupID -> CreateProcess)
-> f (Maybe GroupID) -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Maybe GroupID
x -> CreateProcess
p {Process.child_group = x}) (Maybe GroupID -> f (Maybe GroupID)
f (CreateProcess -> Maybe GroupID
Process.child_group CreateProcess
p))
  child_user :: Lens' CreateProcess (Maybe UserID)
child_user Maybe UserID -> f (Maybe UserID)
f CreateProcess
p =
    (Maybe UserID -> CreateProcess)
-> f (Maybe UserID) -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Maybe UserID
x -> CreateProcess
p {Process.child_user = x}) (Maybe UserID -> f (Maybe UserID)
f (CreateProcess -> Maybe UserID
Process.child_user CreateProcess
p))
  close_fds :: Lens' CreateProcess Bool
close_fds Bool -> f Bool
f CreateProcess
p =
    (Bool -> CreateProcess) -> f Bool -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Bool
x -> CreateProcess
p {Process.close_fds = x}) (Bool -> f Bool
f (CreateProcess -> Bool
Process.close_fds CreateProcess
p))
  create_group :: Lens' CreateProcess Bool
create_group Bool -> f Bool
f CreateProcess
p =
    (Bool -> CreateProcess) -> f Bool -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Bool
x -> CreateProcess
p {Process.create_group = x}) (Bool -> f Bool
f (CreateProcess -> Bool
Process.create_group CreateProcess
p))
  create_new_console :: Lens' CreateProcess Bool
create_new_console Bool -> f Bool
f CreateProcess
p =
    (Bool -> CreateProcess) -> f Bool -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Bool
x -> CreateProcess
p {Process.create_new_console = x}) (Bool -> f Bool
f (CreateProcess -> Bool
Process.create_new_console CreateProcess
p))
  cwd :: Lens' CreateProcess (Maybe FilePath)
cwd Maybe FilePath -> f (Maybe FilePath)
f CreateProcess
p =
    (Maybe FilePath -> CreateProcess)
-> f (Maybe FilePath) -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Maybe FilePath
x -> CreateProcess
p {Process.cwd = x}) (Maybe FilePath -> f (Maybe FilePath)
f (CreateProcess -> Maybe FilePath
Process.cwd CreateProcess
p))
  delegate_ctlc :: Lens' CreateProcess Bool
delegate_ctlc Bool -> f Bool
f CreateProcess
p =
    (Bool -> CreateProcess) -> f Bool -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Bool
x -> CreateProcess
p {Process.delegate_ctlc = x}) (Bool -> f Bool
f (CreateProcess -> Bool
Process.delegate_ctlc CreateProcess
p))
  detach_console :: Lens' CreateProcess Bool
detach_console Bool -> f Bool
f CreateProcess
p =
    (Bool -> CreateProcess) -> f Bool -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Bool
x -> CreateProcess
p {Process.detach_console = x}) (Bool -> f Bool
f (CreateProcess -> Bool
Process.detach_console CreateProcess
p))
  env :: Lens' CreateProcess (Maybe [(FilePath, FilePath)])
env Maybe [(FilePath, FilePath)] -> f (Maybe [(FilePath, FilePath)])
f CreateProcess
p =
    (Maybe [(FilePath, FilePath)] -> CreateProcess)
-> f (Maybe [(FilePath, FilePath)]) -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Maybe [(FilePath, FilePath)]
x -> CreateProcess
p {Process.env = x}) (Maybe [(FilePath, FilePath)] -> f (Maybe [(FilePath, FilePath)])
f (CreateProcess -> Maybe [(FilePath, FilePath)]
Process.env CreateProcess
p))
  new_session :: Lens' CreateProcess Bool
new_session Bool -> f Bool
f CreateProcess
p =
    (Bool -> CreateProcess) -> f Bool -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Bool
x -> CreateProcess
p {Process.new_session = x}) (Bool -> f Bool
f (CreateProcess -> Bool
Process.new_session CreateProcess
p))
  std_err :: Lens' CreateProcess StdStream
std_err StdStream -> f StdStream
f CreateProcess
p =
    (StdStream -> CreateProcess) -> f StdStream -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\StdStream
x -> CreateProcess
p {Process.std_err = x}) (StdStream -> f StdStream
f (CreateProcess -> StdStream
Process.std_err CreateProcess
p))
  std_in :: Lens' CreateProcess StdStream
std_in StdStream -> f StdStream
f CreateProcess
p =
    (StdStream -> CreateProcess) -> f StdStream -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\StdStream
x -> CreateProcess
p {Process.std_in = x}) (StdStream -> f StdStream
f (CreateProcess -> StdStream
Process.std_in CreateProcess
p))
  std_out :: Lens' CreateProcess StdStream
std_out StdStream -> f StdStream
f CreateProcess
p =
    (StdStream -> CreateProcess) -> f StdStream -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\StdStream
x -> CreateProcess
p {Process.std_out = x}) (StdStream -> f StdStream
f (CreateProcess -> StdStream
Process.std_out CreateProcess
p))
  use_process_jobs :: Lens' CreateProcess Bool
use_process_jobs Bool -> f Bool
f CreateProcess
p =
    (Bool -> CreateProcess) -> f Bool -> f CreateProcess
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Bool
x -> CreateProcess
p {Process.use_process_jobs = x}) (Bool -> f Bool
f (CreateProcess -> Bool
Process.use_process_jobs CreateProcess
p))

-- | Type class for values that can be constructed from a @CreateProcess@.
--
-- >>> review reviewCreateProcess (proc "echo" ["hi"]) == proc "echo" ["hi"]
-- True
class ReviewCreateProcess a where
  reviewCreateProcess ::
    Review a CreateProcess

-- |
--
-- >>> review reviewCreateProcess (proc "echo" ["hi"]) == proc "echo" ["hi"]
-- True
instance ReviewCreateProcess CreateProcess where
  reviewCreateProcess :: Review CreateProcess CreateProcess
reviewCreateProcess = (CreateProcess -> CreateProcess)
-> Optic
     p f CreateProcess CreateProcess CreateProcess CreateProcess
forall (p :: * -> * -> *) (f :: * -> *) b t s a.
(Profunctor p, Bifunctor p, Functor f) =>
(b -> t) -> Optic p f s t a b
unto CreateProcess -> CreateProcess
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
  {-# INLINE reviewCreateProcess #-}

-- | Type class for values with a prism into a @CreateProcess@.
--
-- >>> preview _CreateProcess (proc "echo" ["hi"]) == Just (proc "echo" ["hi"])
-- True
class (ReviewCreateProcess a) => AsCreateProcess a where
  _CreateProcess ::
    Prism' a CreateProcess

-- |
--
-- >>> preview _CreateProcess (proc "echo" ["hi"]) == Just (proc "echo" ["hi"])
-- True
instance AsCreateProcess CreateProcess where
  _CreateProcess :: Prism' CreateProcess CreateProcess
_CreateProcess =
    p CreateProcess (f CreateProcess)
-> p CreateProcess (f CreateProcess)
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id

-- |
--
-- >>> toListOf streams (proc "echo" ["hi"])
-- [Inherit,Inherit,Inherit]
-- >>> set streams CreatePipe (proc "echo" ["hi"]) ^. std_in
-- CreatePipe
streams ::
  Traversal' CreateProcess StdStream
streams :: Traversal' CreateProcess StdStream
streams StdStream -> f StdStream
f CreateProcess
p =
  (\StdStream
sti' StdStream
sto' StdStream
ste' -> CreateProcess
p {Process.std_in = sti', Process.std_out = sto', Process.std_err = ste'})
    (StdStream -> StdStream -> StdStream -> CreateProcess)
-> f StdStream -> f (StdStream -> StdStream -> CreateProcess)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StdStream -> f StdStream
f (CreateProcess -> StdStream
Process.std_in CreateProcess
p)
    f (StdStream -> StdStream -> CreateProcess)
-> f StdStream -> f (StdStream -> CreateProcess)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> StdStream -> f StdStream
f (CreateProcess -> StdStream
Process.std_out CreateProcess
p)
    f (StdStream -> CreateProcess) -> f StdStream -> f CreateProcess
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> StdStream -> f StdStream
f (CreateProcess -> StdStream
Process.std_err CreateProcess
p)

-- |
--
-- >>> toListOf streams1 (proc "echo" ["hi"])
-- [Inherit,Inherit,Inherit]
streams1 ::
  Traversal1' CreateProcess StdStream
streams1 :: Traversal1' CreateProcess StdStream
streams1 StdStream -> f StdStream
f CreateProcess
p =
  (\StdStream
sti' StdStream
sto' StdStream
ste' -> CreateProcess
p {Process.std_in = sti', Process.std_out = sto', Process.std_err = ste'})
    (StdStream -> StdStream -> StdStream -> CreateProcess)
-> f StdStream -> f (StdStream -> StdStream -> CreateProcess)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StdStream -> f StdStream
f (CreateProcess -> StdStream
Process.std_in CreateProcess
p)
    f (StdStream -> StdStream -> CreateProcess)
-> f StdStream -> f (StdStream -> CreateProcess)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> StdStream -> f StdStream
f (CreateProcess -> StdStream
Process.std_out CreateProcess
p)
    f (StdStream -> CreateProcess) -> f StdStream -> f CreateProcess
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> StdStream -> f StdStream
f (CreateProcess -> StdStream
Process.std_err CreateProcess
p)