lens-process-0.3.0.1: Optics for system processes

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

System.Process.Lens.CmdSpec

Contents

Description

This module provides the associated optics and combinators for working with CmdSpec objects. CmdSpec consists of two cases: a Shell command, which is a command to execute naively in the shell, and a Raw command which is a command path together with its arguments. As a result, CmdSpec has prisms into those two cases.

There is also a convenient Traversal available for working with the arglist of a Raw command, as well as associated Reviews for each prism, and combinators for working with arguments monoidally.

We provide classy variants for all useful prisms

Synopsis

Traversals

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

Traversal' into the arguments of a command

Examples:

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

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"]

Classy Prisms

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.CmdSpec

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.CmdSpec

Combinators

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"]

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"

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"]