module Development.Shake.Sys (
sys, sysCwd, sysOutput, args
) where
import Development.Shake.Core
import Development.Shake.Derived
type a :-> t = a
sys :: SysArguments v => String -> v :-> Action ()
sys x = sys_ [] x
class SysArguments t where sys_ :: [String] -> t
instance (Arg a, SysArguments r) => SysArguments (a -> r) where
sys_ xs x = sys_ $ xs ++ arg x
instance SysArguments (Action ()) where
sys_ (x:xs) = system' x xs
sys_ [] = error "No executable or arguments given to sys"
sysCwd :: SysCwdArguments v => FilePath -> String -> v :-> Action ()
sysCwd dir x = sysCwd_ dir [] x
class SysCwdArguments t where sysCwd_ :: FilePath -> [String] -> t
instance (Arg a, SysCwdArguments r) => SysCwdArguments (a -> r) where
sysCwd_ dir xs x = sysCwd_ dir $ xs ++ arg x
instance SysCwdArguments (Action ()) where
sysCwd_ dir (x:xs) = systemCwd dir x xs
sysCwd_ dir [] = error "No executable or arguments given to sysCwd"
sysOutput :: SysOutputArguments v => String -> v :-> Action (String, String)
sysOutput x = sysOutput_ [] x
class SysOutputArguments t where sysOutput_ :: [String] -> t
instance (Arg a, SysOutputArguments r) => SysOutputArguments (a -> r) where
sysOutput_ xs x = sysOutput_ $ xs ++ arg x
instance SysOutputArguments (Action (String, String)) where
sysOutput_ (x:xs) = systemOutput x xs
sysOutput_ [] = error "No executable or arguments given to sys"
args :: ArgsArguments v => v :-> [String]
args = args_ []
class ArgsArguments t where args_ :: [String] -> t
instance (Arg a, ArgsArguments r) => ArgsArguments (a -> r) where
args_ xs x = args_ $ xs ++ arg x
instance ArgsArguments [String] where
args_ = id
class Arg a where arg :: a -> [String]
instance Arg String where arg = words
instance Arg [String] where arg = id