FsMake


Cmd Module

Module for building and executing commands or processes.

Example

 let step = Step.create "mStep" {
     do! Cmd.createWithArgs "dotnet" [ "build" ] |> Cmd.run
     let! result = Cmd.createWithArgs "dotnet" [ "gitversion" ] |> Cmd.result
     printfn "%s" result.Output.Std
 }

Types

Type Description

Arg

Argument types.

CmdOptions<'a>

Contains all the options used to run a process.

ExitCodeCheckOption

Process exit code check options.

OutputProcessorArgs

Type representing the arguments passed to an output processor function.

PrefixOption

Prefix options, sets when to prefix the output with the step name.

ProcessResult<'a>

Contains the exit code and output of a process (if redirected).

RedirectOption

Output redirection options.

RedirectedOutput

Contains the redirected std and stderr output of a process.

Functions and values

Function or value Description

argMaybe cond arg opts

Full Usage: argMaybe cond arg opts

Parameters:
    cond : bool - The condition.
    arg : string - The argument to append.
    opts : CmdOptions<'a> - The CmdOptions to append to.

Returns: CmdOptions<'a> The updated CmdOptions.

**Appends** the given argument to the CmdOptions if the condition is true.

cond : bool

The condition.

arg : string

The argument to append.

opts : CmdOptions<'a>

The CmdOptions to append to.

Returns: CmdOptions<'a>

The updated CmdOptions.

argOption arg opts

Full Usage: argOption arg opts

Parameters:
    arg : string option - The argument to append.
    opts : CmdOptions<'a> - The CmdOptions to append to.

Returns: CmdOptions<'a> The updated CmdOptions.

**Appends** the given argument to the CmdOptions if the option Some.

arg : string option

The argument to append.

opts : CmdOptions<'a>

The CmdOptions to append to.

Returns: CmdOptions<'a>

The updated CmdOptions.

argSecret arg opts

Full Usage: argSecret arg opts

Parameters:
Returns: CmdOptions<'a> The updated CmdOptions.

**Appends** the given *secret* argument to the CmdOptions. Secret arguments are masked in console output.

arg : string

The argument to append.

opts : CmdOptions<'a>

The CmdOptions to append to.

Returns: CmdOptions<'a>

The updated CmdOptions.

args args opts

Full Usage: args args opts

Parameters:
    args : string list - The arguments to append.
    opts : CmdOptions<'a> - The CmdOptions to append to.

Returns: CmdOptions<'a> The updated CmdOptions.

**Appends** the given arguments to the CmdOptions.

args : string list

The arguments to append.

opts : CmdOptions<'a>

The CmdOptions to append to.

Returns: CmdOptions<'a>

The updated CmdOptions.

argsMaybe cond args opts

Full Usage: argsMaybe cond args opts

Parameters:
    cond : bool - The condition.
    args : string list - The arguments to append.
    opts : CmdOptions<'a> - The CmdOptions to append to.

Returns: CmdOptions<'a> The updated CmdOptions.

**Appends** the given arguments to the CmdOptions if the condition is true.

cond : bool

The condition.

args : string list

The arguments to append.

opts : CmdOptions<'a>

The CmdOptions to append to.

Returns: CmdOptions<'a>

The updated CmdOptions.

argsOption args' opts

Full Usage: argsOption args' opts

Parameters:
    args' : string list option - The arguments to append.
    opts : CmdOptions<'a> - The CmdOptions to append to.

Returns: CmdOptions<'a> The updated CmdOptions.

**Appends** the given arguments to the CmdOptions if the option Some.

args' : string list option

The arguments to append.

opts : CmdOptions<'a>

The CmdOptions to append to.

Returns: CmdOptions<'a>

The updated CmdOptions.

checkExitCode check opts

Full Usage: checkExitCode check opts

Parameters:
Returns: CmdOptions<'a> The updated CmdOptions.

Sets the check exit code option on the CmdOptions. This sets if the exit code returned by the process should be checked. Check the options in ExitCodeCheckOption for more information on each option. The default is CheckCodeZero.

check : ExitCodeCheckOption

The exit code check option.

opts : CmdOptions<'a>

The CmdOptions.

Returns: CmdOptions<'a>

The updated CmdOptions.

Example

 let! output =
     Cmd.createWithArgs "dotnet" [ "build" ]
     |> Cmd.checkExitCode Cmd.CheckCodeNone
     |> Cmd.result

create cmd

Full Usage: create cmd

Parameters:
    cmd : string - The command to run.

Returns: CmdOptions<unit> The new CmdOptions.

Creates a CmdOptions with a command to run.

cmd : string

The command to run.

Returns: CmdOptions<unit>

The new CmdOptions.

createWithArgs cmd args

Full Usage: createWithArgs cmd args

Parameters:
    cmd : string - The command to run.
    args : string list - A list of arguments to be passed to the command.

Returns: CmdOptions<unit> The new CmdOptions.

Creates a CmdOptions with a command to run.

cmd : string

The command to run.

args : string list

A list of arguments to be passed to the command.

Returns: CmdOptions<unit>

The new CmdOptions.

Example

 let cmd = Cmd.createWithArgs "dotnet" [ "build"; "--no-restore" ]

envVars envVars opts

Full Usage: envVars envVars opts

Parameters:
    envVars : (string * string) list - A key * value tuple list of environment variables to append.
    opts : CmdOptions<'a> - The CmdOptions to append to.

Returns: CmdOptions<'a> The updated CmdOptions.

**Appends** the given environment variables to the CmdOptions.

envVars : (string * string) list

A key * value tuple list of environment variables to append.

opts : CmdOptions<'a>

The CmdOptions to append to.

Returns: CmdOptions<'a>

The updated CmdOptions.

Example

 Cmd.createWithArgs "docker-compose" [ "build" ]
 |> Cmd.envVars [ ("DEBUG", "0"); ("TAG", "1.0.0") ]

prefix prefix opts

Full Usage: prefix prefix opts

Parameters:
Returns: CmdOptions<'a> The updated CmdOptions.

Sets the prefix option on the CmdOptions. This sets if the console output will be prefixed with the step name.

prefix : PrefixOption

The prefix option.

opts : CmdOptions<'a>

The CmdOptions.

Returns: CmdOptions<'a>

The updated CmdOptions.

redirectOutput redirect opts

Full Usage: redirectOutput redirect opts

Parameters:
Returns: CmdOptions<RedirectedOutput> The updated CmdOptions.

Sets the redirect option on the CmdOptions. This controls how the output of the process should be redirected. Check the options in RedirectOption for more information on each option.

redirect : RedirectOption

The redirect option.

opts : CmdOptions<'a>

The CmdOptions.

Returns: CmdOptions<RedirectedOutput>

The updated CmdOptions.

Example

 let! output =
     Cmd.createWithArgs "dotnet" [ "build" ]
     |> Cmd.redirectOutput Cmd.RedirectToBoth
     |> Cmd.result

result opts ctx

Full Usage: result opts ctx

Parameters:
Returns: Result<ProcessResult<'a>, MakeError> The result.

Runs a command/process with the specified options and returns a ProcessResult. The ProcessResult contains the exit code and optionally the redirected output if a redirect option was set. This method cannot be used if the output has not been redirected.

opts : CmdOptions<'a>

The CmdOptions.

ctx : MakeContext

The MakeContext of the current Make.

Returns: Result<ProcessResult<'a>, MakeError>

The result.

Example

 let myStep =
     Step.create "myStep" {
         let! semverResult =
             Cmd.createWithArgs "dotnet" [ "gitversion"; "/showvariable"; "semver" ]
             |> Cmd.redirectOutput Cmd.Redirect
             |> Cmd.result

         let semver = semverResult.Output.Std
     }

run opts ctx

Full Usage: run opts ctx

Parameters:
Returns: Result<unit, MakeError> The result.

Runs a command/process with the specified options.

opts : CmdOptions<'a>

The CmdOptions.

ctx : MakeContext

The MakeContext of the current Make.

Returns: Result<unit, MakeError>

The result.

Example

 let build =
     Step.create "build" {
         do! Cmd.createWithArgs "dotnet" [ "build" ] |> Cmd.run
     }

timeout seconds opts

Full Usage: timeout seconds opts

Parameters:
Returns: CmdOptions<'a> The updated CmdOptions.

Sets the timeout option on the CmdOptions. This is the time in seconds before the command times out and is terminated. The timeout being reached causes a step failure.

seconds : int

The timeout in seconds.

opts : CmdOptions<'a>

The CmdOptions.

Returns: CmdOptions<'a>

The updated CmdOptions.

workingDir path opts

Full Usage: workingDir path opts

Parameters:
Returns: CmdOptions<'a> The updated CmdOptions.

Sets the working directory on the CmdOptions.

path : string

The path of the working directory.

opts : CmdOptions<'a>

The CmdOptions.

Returns: CmdOptions<'a>

The updated CmdOptions.