| Copyright | (c) 2019-2021 Emily Pillmore |
|---|---|
| License | BSD |
| Maintainer | Emily Pillmore <emilypi@cohomolo.gy> |
| Stability | Experimental |
| Portability | TypeFamilies |
| Safe Haskell | None |
| Language | Haskell2010 |
System.Process.Lens.CmdSpec
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
Traversals
arguments :: AsRaw 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" ^? _ShellCommandJust "ls -l"
>>>RawCommand "/bin/ls" ["-l"] ^? _ShellCommandNothing
_RawCommand :: Prism' CmdSpec (FilePath, [String]) Source #
A prism into the RawCommand case of a CmdSpec
Examples:
>>>RawCommand "/bin/ls" ["-l"] ^? _RawCommandJust ("/bin/ls",["-l"])
>>>RawCommand "/bin/ls" ["-l"] ^? _ShellCommandNothing
>>>RawCommand "/bin/ls" ["-l"] ^. _RawCommand . _1"/bin/ls"
>>>RawCommand "/bin/ls" ["-l"] ^. _RawCommand . _2["-l"]
Classy Prisms
class AsShell a where Source #
Classy prism into the shell command of a CmdSpec
Examples:
>>>f :: AsShell a => a -> Maybe String; f = preview _Shell>>>f $ _ShellCommand # "ls -l"Just "ls -l"
Classy prism into the raw command of a CmdSpec
Examples:
>>>f :: AsRaw a => a -> Maybe FilePath; f = preview (_Raw . _1)>>>f $ _RawCommand # ("/bin/ls", ["ls -l"])Just "/bin/ls"
Combinators
arguing :: AsRaw 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"]