lens-process-0.2.0.2: Optics for system processes

Copyright2019 Emily Pillmore
LicenseBSD
MaintainerEmily Pillmore <emilypi@cohomolo.gy>
StabilityExperimental
PortabilityTypeFamilies, RankNTypes
Safe HaskellSafe
LanguageHaskell2010

System.Process.Lens

Contents

Description

This module provides all of the optical exports, as well ask any associated combinators. For just the optics, see Optics, or if you are in need of something lighter weight, just for working with a CreateProcess in terms of getters and setters, see https://hackage.haskell.org/package/microlens

For more information on usage and how to work with lenses, see http://github.com/ekmett/lens/wiki and the tests for example uses. You can also ask questions on Freenode in the #haskell-lens channel.

Synopsis

Data

data ProcessHandler Source #

A convenient handler for the output of a createProcess call. This data containes 4 components:

  1. a handle to stdin if it was requested
  2. a handle to stdout if it was requested
  3. a handle to stderr if it was requested
  4. a process handle, containing a pid lock, information regarding ctcl-c delegation, and closed/open handle status info.

Prisms

_ShellCommand :: Prism' CmdSpec String Source #

A prism into the ShellCommand case of a CmdSpec

Examples:

>>> _ShellCommand # "ls -l"
ShellCommand "ls -l"
>>> ShellCommand "ls -l" ^? _ShellCommand
Just "ls -l"
>>> RawCommand "/bin/ls" ["-l"] ^? _ShellCommand
Nothing

_RawCommand :: Prism' CmdSpec (FilePath, [String]) Source #

A prism into the RawCommand case of a CmdSpec

Examples:

>>> RawCommand "/bin/ls" ["-l"] ^? _RawCommand
Just ("/bin/ls",["-l"])
>>> RawCommand "/bin/ls" ["-l"] ^? _ShellCommand
Nothing
>>> RawCommand "/bin/ls" ["-l"] ^. _RawCommand . _1
"/bin/ls"
>>> RawCommand "/bin/ls" ["-l"] ^. _RawCommand . _2
["-l"]

arguments :: IsRaw a => Traversal' a [String] Source #

Traversal' into the arguments of a command

Examples:

>>> RawCommand "/bin/ls" ["-l"] ^. arguments
["-l"]

_Inherit :: Prism' StdStream StdStream Source #

A prism into the Inherit structure of a StdStream

Examples:

>>> _Inherit # CreatePipe
Inherit

_UseHandle :: Prism' StdStream Handle Source #

A prism into the UseHandle structure's Handle for a StdStream

Examples:

>>> _UseHandle # System.stdin
UseHandle {handle: <stdin>}

_CreatePipe :: Prism' StdStream StdStream Source #

A prism into the CreatePipe structure of a StdStream

Examples:

>>> _CreatePipe # Inherit
CreatePipe

_NoStream :: Prism' StdStream StdStream Source #

A prism into the NoStream structure of a StdStream

Examples:

>>> _NoStream # CreatePipe
NoStream

Isos

_Handler :: Iso' ProcessHandler (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) Source #

An iso between the ProcessHandler data and its product representation

Lenses

cmdspec_ :: Lens' CreateProcess CmdSpec Source #

Lens into the cmdspec entry of the CreateProcess record

cwd_ :: Lens' CreateProcess (Maybe FilePath) Source #

Lens into the cwd entry of the CreateProcess record

env_ :: Lens' CreateProcess (Maybe [(String, String)]) Source #

Lens into the env entry of the CreateProcess record

stdin_ :: Lens' CreateProcess StdStream Source #

Lens into the std_in entry of the CreateProcess record

stdout_ :: Lens' CreateProcess StdStream Source #

Lens into the std_out entry of the CreateProcess record

stderr_ :: Lens' CreateProcess StdStream Source #

Lens into the std_err entry of the CreateProcess record

closefds :: Lens' CreateProcess Bool Source #

Lens into the close_fds entry of the CreateProcess record

newsession :: Lens' CreateProcess Bool Source #

Lens into the new_session entry of the CreateProcess record

childgroup :: Lens' CreateProcess (Maybe CGid) Source #

Lens into the child_group entry of the CreateProcess record

childuser :: Lens' CreateProcess (Maybe CUid) Source #

Lens into the child_user entry of the CreateProcess record

hstdin :: Lens' ProcessHandler (Maybe Handle) Source #

A lens into the stdin handle if requested

hstdout :: Lens' ProcessHandler (Maybe Handle) Source #

A lens into the stdout handle if requested

hstderr :: Lens' ProcessHandler (Maybe Handle) Source #

A lens into the stderr handle if requested

hhandle :: Lens' ProcessHandler ProcessHandle Source #

A lens into the process handle

Classes

class IsRaw a where Source #

Classy prism into the raw command of a CmdSpec

Examples:

>>> f :: IsRaw a => a -> Maybe FilePath; f = preview (_Raw . _1)
>>> f $ _RawCommand # ("/bin/ls", ["ls -l"])
Just "/bin/ls"

Methods

_Raw :: Prism' a (FilePath, [String]) Source #

Instances
IsRaw CmdSpec Source # 
Instance details

Defined in System.Process.Lens.CommandSpec

class IsShell a where Source #

Classy prism into the shell command of a CmdSpec

Examples:

>>> f :: IsShell a => a -> Maybe String; f = preview _Shell
>>> f $ _ShellCommand # "ls -l"
Just "ls -l"
Instances
IsShell CmdSpec Source # 
Instance details

Defined in System.Process.Lens.CommandSpec

class IsInherit a where Source #

Class constraint proving a type has a prism into an Inherit structure. Any StdStream will have a prism into Inherit - it is just an overwrite to Inherit

class IsUseHandle a where Source #

Class constraint proving a type has a prism into a Handle via a UseHandle structure.

class IsCreatePipe a where Source #

Class constraint proving a type has a prism into a Handle via a UseHandle structure. Any StdStream will have a prism into CreatePipe - it is just an overwrite to CreatePipe

class IsNoStream a where Source #

Class constraint proving a type has a prism into a Handle via a UseHandle structure. Any StdStream will have a prism into NoStream - it is just an overwrite to NoStream.

class HasStdin a where Source #

Classy lens for types with a stdin

class HasStdout a where Source #

Classy lens for types with a stdout

class HasStderr a where Source #

Classy lens for types with a stderr

Combinators

inheriting :: IsInherit a => Lens' a StdStream -> a -> a Source #

Given a lens into a StdStream, overwrite to Inherit so that the stream inherits from its parent process

Examples:

>>> inheriting ($) CreatePipe
Inherit

piping :: IsCreatePipe a => Lens' a StdStream -> a -> a Source #

Given a lens into a StdStream, overwrite to CreatePipe.

Examples:

>>> piping ($) NoStream
CreatePipe

handling :: IsUseHandle a => Lens' a StdStream -> Handle -> a -> a Source #

Given a lens into a StdStream and a handle, set the handle using UseHandle. Note that this is the only really interesting case for anything with a lens into a handle inculding StdStream.

Examples:

>>> handling ($) System.stdin $ UseHandle System.stdout
UseHandle {handle: <stdin>}
>>> handling ($) System.stdin NoStream
NoStream
>>> handling ($) System.stdin Inherit
Inherit

nostreaming :: IsNoStream a => Lens' a StdStream -> a -> a Source #

Given a lens into a StdStream, set to NoStream

Examples:

>>> nostreaming ($) Inherit
NoStream

arguing :: IsRaw a => String -> a -> a Source #

Append an argument to the argument list of a RawCommand

Examples:

>>> arguing "-h" $ RawCommand "/bin/ls" ["-l"]
RawCommand "/bin/ls" ["-l","-h"]
>>> arguing "-h" (RawCommand "/bin/ls" ["-l"]) ^. arguments
["-l","-h"]

rawOf :: IsRaw a => FilePath -> [String] -> a Source #

Lift a FilePath and list of arguments into a type via RawCommand with a prism into the command

Examples:

>>> rawOf @CmdSpec "/bin/ls" ["-l"]
RawCommand "/bin/ls" ["-l"]

shellOf :: IsShell a => String -> a Source #

Lift a String into a type via ShellCommand with a prism into the

Examples:

>>> shellOf @CmdSpec "ls"
ShellCommand "ls"

usehandleOf :: IsUseHandle a => Handle -> a Source #

Inject a handle into something with a prism into the handle

Examples:

>>> usehandleOf @StdStream System.stdin
UseHandle {handle: <stdin>}