{-# LANGUAGE TypeFamilies #-}
module System.Process.Lens.CmdSpec
(
arguments
, _ShellCommand
, _RawCommand
, IsShell(..)
, IsRaw(..)
, arguing
, shellOf
, rawOf
) where
import Control.Lens
import System.Process
_ShellCommand :: Prism' CmdSpec String
_ShellCommand :: p String (f String) -> p CmdSpec (f CmdSpec)
_ShellCommand = (String -> CmdSpec)
-> (CmdSpec -> Maybe String) -> Prism CmdSpec CmdSpec String String
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' String -> CmdSpec
ShellCommand ((CmdSpec -> Maybe String)
-> p String (f String) -> p CmdSpec (f CmdSpec))
-> (CmdSpec -> Maybe String)
-> p String (f String)
-> p CmdSpec (f CmdSpec)
forall a b. (a -> b) -> a -> b
$ \c :: CmdSpec
c -> case CmdSpec
c of
ShellCommand s :: String
s -> String -> Maybe String
forall a. a -> Maybe a
Just String
s
_ -> Maybe String
forall a. Maybe a
Nothing
_RawCommand :: Prism' CmdSpec (FilePath, [String])
_RawCommand :: p (String, [String]) (f (String, [String]))
-> p CmdSpec (f CmdSpec)
_RawCommand = ((String, [String]) -> CmdSpec)
-> (CmdSpec -> Maybe (String, [String]))
-> Prism CmdSpec CmdSpec (String, [String]) (String, [String])
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((String -> [String] -> CmdSpec) -> (String, [String]) -> CmdSpec
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry String -> [String] -> CmdSpec
RawCommand) ((CmdSpec -> Maybe (String, [String]))
-> p (String, [String]) (f (String, [String]))
-> p CmdSpec (f CmdSpec))
-> (CmdSpec -> Maybe (String, [String]))
-> p (String, [String]) (f (String, [String]))
-> p CmdSpec (f CmdSpec)
forall a b. (a -> b) -> a -> b
$ \c :: CmdSpec
c -> case CmdSpec
c of
RawCommand fp :: String
fp s :: [String]
s -> (String, [String]) -> Maybe (String, [String])
forall a. a -> Maybe a
Just (String
fp, [String]
s)
_ -> Maybe (String, [String])
forall a. Maybe a
Nothing
class IsShell a where
_Shell :: Prism' a String
{-# MINIMAL _Shell #-}
instance IsShell CmdSpec where
_Shell :: p String (f String) -> p CmdSpec (f CmdSpec)
_Shell = p String (f String) -> p CmdSpec (f CmdSpec)
Prism CmdSpec CmdSpec String String
_ShellCommand
class IsRaw a where
_Raw :: Prism' a (FilePath, [String])
{-# MINIMAL _Raw #-}
instance IsRaw CmdSpec where
_Raw :: p (String, [String]) (f (String, [String]))
-> p CmdSpec (f CmdSpec)
_Raw = p (String, [String]) (f (String, [String]))
-> p CmdSpec (f CmdSpec)
Prism CmdSpec CmdSpec (String, [String]) (String, [String])
_RawCommand
arguments :: IsRaw a => Traversal' a [String]
arguments :: Traversal' a [String]
arguments = ((String, [String]) -> f (String, [String])) -> a -> f a
forall a. IsRaw a => Prism' a (String, [String])
_Raw (((String, [String]) -> f (String, [String])) -> a -> f a)
-> (([String] -> f [String])
-> (String, [String]) -> f (String, [String]))
-> ([String] -> f [String])
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([String] -> f [String])
-> (String, [String]) -> f (String, [String])
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
arguing :: IsRaw a => String -> a -> a
arguing :: String -> a -> a
arguing s :: String
s = ([String] -> Identity [String]) -> a -> Identity a
forall a. IsRaw a => Traversal' a [String]
arguments (([String] -> Identity [String]) -> a -> Identity a)
-> [String] -> a -> a
forall a s t. Monoid a => ASetter s t a a -> a -> s -> t
<>~ [String
s]
shellOf :: IsShell a => String -> a
shellOf :: String -> a
shellOf = AReview a String -> String -> a
forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review AReview a String
forall a. IsShell a => Prism' a String
_Shell
rawOf :: IsRaw a => FilePath -> [String] -> a
rawOf :: String -> [String] -> a
rawOf fp :: String
fp ss :: [String]
ss = Tagged (String, [String]) (Identity (String, [String]))
-> Tagged a (Identity a)
forall a. IsRaw a => Prism' a (String, [String])
_Raw (Tagged (String, [String]) (Identity (String, [String]))
-> Tagged a (Identity a))
-> (String, [String]) -> a
forall t b. AReview t b -> b -> t
# (String
fp, [String]
ss)