Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- command :: (Partial, CmdResult r, MonadAction m) => [CmdOption] -> String -> [String] -> m r
- command_ :: (Partial, MonadAction m) => [CmdOption] -> String -> [String] -> m ()
- cmd :: (Partial, CmdArguments args) => args :-> Action r
- cmd_ :: (Partial, CmdArguments args, Unit args) => args :-> Action ()
- unit :: m () -> m ()
- newtype CmdArgument = CmdArgument [Either CmdOption String]
- class CmdArguments t where
- cmdArguments :: CmdArgument -> t
- class IsCmdArgument a where
- toCmdArgument :: a -> CmdArgument
- type (:->) a t = a
- newtype Stdout a = Stdout {
- fromStdout :: a
- newtype StdoutTrim a = StdoutTrim {
- fromStdoutTrim :: a
- newtype Stderr a = Stderr {
- fromStderr :: a
- newtype Stdouterr a = Stdouterr {
- fromStdouterr :: a
- newtype Exit = Exit {}
- newtype Process = Process {}
- newtype CmdTime = CmdTime {}
- newtype CmdLine = CmdLine {}
- data FSATrace a
- class CmdResult a
- class CmdString a
- data CmdOption
- = Cwd FilePath
- | Env [(String, String)]
- | AddEnv String String
- | RemEnv String
- | AddPath [String] [String]
- | Stdin String
- | StdinBS ByteString
- | FileStdin FilePath
- | Shell
- | BinaryPipes
- | Traced String
- | Timeout Double
- | WithStdout Bool
- | WithStderr Bool
- | EchoStdout Bool
- | EchoStderr Bool
- | FileStdout FilePath
- | FileStderr FilePath
- | AutoDeps
- | UserCommand String
- | FSAOptions String
- | CloseFileHandles
- | NoProcessGroup
- | InheritStdin
Documentation
command :: (Partial, CmdResult r, MonadAction m) => [CmdOption] -> String -> [String] -> m r Source #
Lifted version of command
.
command_ :: (Partial, MonadAction m) => [CmdOption] -> String -> [String] -> m () Source #
Lifted version of command_
.
cmd :: (Partial, CmdArguments args) => args :-> Action r #
Build or execute a system command. Before using cmd
to run a command, make sure you need
any files
that are used by the command.
String
arguments are treated as a list of whitespace separated arguments.[String]
arguments are treated as a list of literal arguments.CmdOption
arguments are used as options.CmdArgument
arguments, which can be built bycmd
itself, are spliced into the containing command.
Typically only string literals should be passed as String
arguments. When using variables
prefer [myvar]
so that if myvar
contains spaces they are properly escaped.
As some examples, here are some calls, and the resulting command string:
cmd_
"git log --pretty=" "oneline" -- git log --pretty= onelinecmd_
"git log --pretty=" ["oneline"] -- git log --pretty= onelinecmd_
"git log" ("--pretty=" ++ "oneline") -- git log --pretty=onelinecmd_
"git log" ("--pretty=" ++ "one line") -- git log --pretty=one linecmd_
"git log" ["--pretty=" ++ "one line"] -- git log "--pretty=one line"
More examples, including return values, see this translation of the examples given for the command
function:
cmd_
"gcc -c myfile.c" -- compile a file, throwing an exception on failureExit
c <-cmd
"gcc -c" [myfile] -- run a command, recording the exit code (Exit
c,Stderr
err) <-cmd
"gcc -c myfile.c" -- run a command, recording the exit code and error outputStdout
out <-cmd
"gcc -MM myfile.c" -- run a command, recording the outputcmd
(Cwd
"generated") "gcc -c" [myfile] ::Action
() -- run a command in a directory let gccCommand =cmd
"gcc -c" ::CmdArgument
-- build a sub-command.cmd
can returnCmdArgument
values as well as execute commands cmd (Cwd
"generated") gccCommand [myfile] -- splice that command into a greater command
If you use cmd
inside a do
block and do not use the result, you may get a compile-time error about being
unable to deduce CmdResult
. To avoid this error, use cmd_
. If you enable OverloadedStrings
or OverloadedLists
you may have to give type signatures to the arguments, or use the more constrained command
instead.
The cmd
function can also be run in the IO
monad, but then Traced
is ignored and command lines are not echoed.
As an example:
cmd
(Cwd
"generated")Shell
"gcc -c myfile.c" :: IO ()
The identity function which requires the inner argument to be ()
. Useful for functions
with overloaded return types.
\(x :: Maybe ()) -> unit x == x
newtype CmdArgument #
Instances
Eq CmdArgument | |
Defined in Development.Shake.Command (==) :: CmdArgument -> CmdArgument -> Bool # (/=) :: CmdArgument -> CmdArgument -> Bool # | |
Show CmdArgument | |
Defined in Development.Shake.Command showsPrec :: Int -> CmdArgument -> ShowS # show :: CmdArgument -> String # showList :: [CmdArgument] -> ShowS # | |
Semigroup CmdArgument | |
Defined in Development.Shake.Command (<>) :: CmdArgument -> CmdArgument -> CmdArgument # sconcat :: NonEmpty CmdArgument -> CmdArgument # stimes :: Integral b => b -> CmdArgument -> CmdArgument # | |
Monoid CmdArgument | |
Defined in Development.Shake.Command mempty :: CmdArgument # mappend :: CmdArgument -> CmdArgument -> CmdArgument # mconcat :: [CmdArgument] -> CmdArgument # | |
CmdArguments CmdArgument | |
Defined in Development.Shake.Command cmdArguments :: CmdArgument -> CmdArgument # | |
IsCmdArgument CmdArgument | |
Defined in Development.Shake.Command toCmdArgument :: CmdArgument -> CmdArgument # |
class CmdArguments t where #
cmdArguments :: CmdArgument -> t #
Arguments to cmd
Instances
CmdArguments CmdArgument | |
Defined in Development.Shake.Command cmdArguments :: CmdArgument -> CmdArgument # | |
CmdResult r => CmdArguments (IO r) | |
Defined in Development.Shake.Command cmdArguments :: CmdArgument -> IO r # | |
CmdResult r => CmdArguments (Action r) | |
Defined in Development.Shake.Command cmdArguments :: CmdArgument -> Action r # | |
(IsCmdArgument a, CmdArguments r) => CmdArguments (a -> r) | |
Defined in Development.Shake.Command cmdArguments :: CmdArgument -> a -> r # |
class IsCmdArgument a where #
Class to convert an a to a CmdArgument
toCmdArgument :: a -> CmdArgument #
Conversion to a CmdArgument
Instances
IsCmdArgument () | |
Defined in Development.Shake.Command toCmdArgument :: () -> CmdArgument # | |
IsCmdArgument String | |
Defined in Development.Shake.Command toCmdArgument :: String -> CmdArgument # | |
IsCmdArgument CmdArgument | |
Defined in Development.Shake.Command toCmdArgument :: CmdArgument -> CmdArgument # | |
IsCmdArgument CmdOption | |
Defined in Development.Shake.Command toCmdArgument :: CmdOption -> CmdArgument # | |
IsCmdArgument [String] | |
Defined in Development.Shake.Command toCmdArgument :: [String] -> CmdArgument # | |
IsCmdArgument [CmdOption] | |
Defined in Development.Shake.Command toCmdArgument :: [CmdOption] -> CmdArgument # | |
IsCmdArgument a => IsCmdArgument (Maybe a) | |
Defined in Development.Shake.Command toCmdArgument :: Maybe a -> CmdArgument # | |
IsCmdArgument (NonEmpty String) | |
Defined in Development.Shake.Command toCmdArgument :: NonEmpty String -> CmdArgument # |
A type annotation, equivalent to the first argument, but in variable argument contexts, gives a clue as to what return type is expected (not actually enforced).
Collect the stdout
of the process.
If used, the stdout
will not be echoed to the terminal, unless you include EchoStdout
.
The value type may be either String
, or either lazy or strict ByteString
.
Note that most programs end their output with a trailing newline, so calling
ghc --numeric-version
will result in Stdout
of "6.8.3\n"
. If you want to automatically
trim the resulting string, see StdoutTrim
.
Stdout | |
|
newtype StdoutTrim a #
Like Stdout
but remove all leading and trailing whitespaces.
StdoutTrim | |
|
Instances
CmdString a => CmdResult (StdoutTrim a) | |
Defined in Development.Shake.Command cmdResult :: ([Result], [Result] -> StdoutTrim a) |
Collect the stderr
of the process.
If used, the stderr
will not be echoed to the terminal, unless you include EchoStderr
.
The value type may be either String
, or either lazy or strict ByteString
.
Stderr | |
|
Collect the stdout
and stderr
of the process.
If used, the stderr
and stdout
will not be echoed to the terminal, unless you include EchoStdout
and EchoStderr
.
The value type may be either String
, or either lazy or strict ByteString
.
Stdouterr | |
|
Collect the ExitCode
of the process.
If you do not collect the exit code, any ExitFailure
will cause an exception.
Instances
CmdResult Exit | |
Defined in Development.Shake.Command |
Collect the ProcessHandle
of the process.
If you do collect the process handle, the command will run asyncronously and the call to cmd
/ command
will return as soon as the process is spawned. Any Stdout
/ Stderr
captures will return empty strings.
Instances
CmdResult Process | |
Defined in Development.Shake.Command |
Collect the time taken to execute the process. Can be used in conjunction with CmdLine
to
write helper functions that print out the time of a result.
timer :: (CmdResult
r, MonadIO m) => (forall r .CmdResult
r => m r) -> m r timer act = do (CmdTime
t,CmdLine
x, r) <- act liftIO $ putStrLn $ "Command " ++ x ++ " took " ++ show t ++ " seconds" pure r run :: IO () run = timer $cmd
"ghc --version"
Instances
CmdResult CmdTime | |
Defined in Development.Shake.Command |
Collect the command line used for the process. This command line will be approximate - suitable for user diagnostics, but not for direct execution.
Instances
CmdResult CmdLine | |
Defined in Development.Shake.Command |
The results produced by fsatrace
. All files will be absolute paths.
You can get the results for a cmd
by requesting a value of type
[
.FSATrace
]
FSAWrite a | Writing to a file |
FSARead a | Reading from a file |
FSADelete a | Deleting a file |
FSAMove a a | Moving, arguments destination, then source |
FSAQuery a | Querying/stat on a file |
FSATouch a | Touching a file |
Instances
Functor FSATrace | |
Eq a => Eq (FSATrace a) | |
Data a => Data (FSATrace a) | |
Defined in Development.Shake.Command gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> FSATrace a -> c (FSATrace a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (FSATrace a) # toConstr :: FSATrace a -> Constr # dataTypeOf :: FSATrace a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (FSATrace a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (FSATrace a)) # gmapT :: (forall b. Data b => b -> b) -> FSATrace a -> FSATrace a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FSATrace a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FSATrace a -> r # gmapQ :: (forall d. Data d => d -> u) -> FSATrace a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> FSATrace a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> FSATrace a -> m (FSATrace a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> FSATrace a -> m (FSATrace a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> FSATrace a -> m (FSATrace a) # | |
Ord a => Ord (FSATrace a) | |
Show a => Show (FSATrace a) | |
CmdResult [FSATrace ByteString] | |
Defined in Development.Shake.Command cmdResult :: ([Result], [Result] -> [FSATrace ByteString]) | |
CmdResult [FSATrace FilePath] | |
Defined in Development.Shake.Command |
A class for specifying what results you want to collect from a process.
Values are formed of Stdout
, Stderr
, Exit
and tuples of those.
cmdResult
Instances
The allowable String
-like values that can be captured.
cmdString
Instances
CmdString () | |
Defined in Development.Shake.Command cmdString :: (Str, Str -> ()) | |
CmdString ByteString | |
Defined in Development.Shake.Command cmdString :: (Str, Str -> ByteString) | |
CmdString ByteString | |
Defined in Development.Shake.Command cmdString :: (Str, Str -> ByteString) | |
CmdString String | |
Defined in Development.Shake.Command |
Options passed to command
or cmd
to control how processes are executed.
Cwd FilePath | Change the current directory in the spawned process. By default uses this processes current directory.
Successive |
Env [(String, String)] | Change the environment variables in the spawned process. By default uses this processes environment. |
AddEnv String String | Add an environment variable in the child process. |
RemEnv String | Remove an environment variable from the child process. |
AddPath [String] [String] | Add some items to the prefix and suffix of the |
Stdin String | Given as the |
StdinBS ByteString | Given as the |
FileStdin FilePath | Take the |
Shell | Pass the command to the shell without escaping - any arguments will be joined with spaces. By default arguments are escaped properly. |
BinaryPipes | Treat the |
Traced String | Name to use with |
Timeout Double | Abort the computation after N seconds, will raise a failure exit code. Calls |
WithStdout Bool | Should I include the |
WithStderr Bool | Should I include the |
EchoStdout Bool | Should I echo the |
EchoStderr Bool | Should I echo the |
FileStdout FilePath | Should I put the |
FileStderr FilePath | Should I put the |
AutoDeps | Compute dependencies automatically. Only works if |
UserCommand String | The command the user thinks about, before any munging. Defaults to the actual command. |
FSAOptions String | Options to |
CloseFileHandles | Before starting the command in the child process, close all file handles except stdin, stdout, stderr in the child process. Uses |
NoProcessGroup | Don't run the process in its own group. Required when running |
InheritStdin | Cause the stdin from the parent to be inherited. Might also require NoProcessGroup on Linux. Ignored if you explicitly pass a stdin. |
Instances
Eq CmdOption | |
Data CmdOption | |
Defined in Development.Shake.Internal.CmdOption gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CmdOption -> c CmdOption # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CmdOption # toConstr :: CmdOption -> Constr # dataTypeOf :: CmdOption -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c CmdOption) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CmdOption) # gmapT :: (forall b. Data b => b -> b) -> CmdOption -> CmdOption # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CmdOption -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CmdOption -> r # gmapQ :: (forall d. Data d => d -> u) -> CmdOption -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> CmdOption -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CmdOption -> m CmdOption # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CmdOption -> m CmdOption # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CmdOption -> m CmdOption # | |
Ord CmdOption | |
Defined in Development.Shake.Internal.CmdOption | |
Show CmdOption | |
IsCmdArgument CmdOption | |
Defined in Development.Shake.Command toCmdArgument :: CmdOption -> CmdArgument # | |
IsCmdArgument [CmdOption] | |
Defined in Development.Shake.Command toCmdArgument :: [CmdOption] -> CmdArgument # |