Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Console
open Axial.FileSystem
open Axial.PlatformService
open Axial.ProcessOpen Axial.Process.DSL for command-line-shaped authoring:
Show page setup
// Setup for the checked examples on this page.
open System
open Axial
open Axial.Console
open Axial.FileSystem
open Axial.PlatformService
open Axial.Process
open Axial.Process.DSL
/// Fails the docs test when an example's result differs from the value shown.
let shouldEqual expected actual =
if actual <> expected then failwithf "Expected %A but got %A" expected actualopen Axial.Process.DSL
let connect (deviceId: string) (workspace: string) =
cmd $"printf %%s {deviceId}"
|> cwd workspace
|> env "DEVICE_MODE" "service"
|> timeout (TimeSpan.FromSeconds 30.0)
AxialProcessAxial.Process.DSLconnect: string -> string -> ProcessCommanddeviceId: stringstringAn abbreviation for the CLI type . Basic Types
workspace: stringcmd: FormattableString -> ProcessCommand(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
cwd: string -> ProcessCommand -> ProcessCommandenv: string -> string -> ProcessCommand -> ProcessCommandtimeout: TimeSpan -> ProcessCommand -> ProcessCommandSystem.TimeSpanRepresents a time interval.
FromSeconds: float -> TimeSpanReturns a that represents a specified number of seconds, where the specification is accurate to the nearest millisecond. A number of seconds, accurate to the nearest millisecond. An object that represents . is less than or greater than . -or- is . -or- is . is equal to .
Requires & types
Requires: open Axial.Process.DSL; open System (packages: Axial.Process)val connect: string -> string -> ProcessCommandconnect "sensor 7; date" (IO.Path.GetTempPath())
|> Process.run
|> _.StdOut
|> shouldEqual "sensor 7; date"
connect: string -> string -> ProcessCommandIOGetTempPath: unit -> stringReturns the path of the current user's temporary folder. The path to the temporary folder, ending with a backslash. The caller does not have the required permissions.
System.IO.PathPerforms operations on instances that contain file or directory path information. These operations are performed in a cross-platform manner.
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.Processrun: ^source -> ^resultRuns with live services and returns the value; raises ProcessRunException on failure.
_arg1: ProcessResultStdOut: stringshouldEqual: 'a -> 'a -> unitRequires & types
Requires: open Axial.Process (packages: Axial.Process)Interpolation holes remain individual native arguments. Here ; date is returned as text; it does not start another
command. No shell parses the value. Mark sensitive values explicitly:
let authenticate (token: string) =
cmd $"printf %%s {secret token}"
authenticate: string -> ProcessCommandtoken: stringstringAn abbreviation for the CLI type . Basic Types
cmd: FormattableString -> ProcessCommandRequires & types
Requires: open Axial.Process.DSL (packages: Axial.Process)val authenticate: string -> ProcessCommandauthenticate "s3cret" |> Process.render |> shouldEqual "printf \"%s\" ***"
authenticate "s3cret" |> Process.run |> _.StdOut |> shouldEqual "s3cret"
authenticate: string -> ProcessCommand(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.Processrender: ^a -> stringshouldEqual: 'a -> 'a -> unitrun: ^source -> ^resultRuns with live services and returns the value; raises ProcessRunException on failure.
_arg1: ProcessResultStdOut: stringRequires & types
Requires: open Axial.Process (packages: Axial.Process)The real value reaches the process; renders, plans, and errors show ***.
Use bash, sh, or pwsh when shell syntax is required. Interpolated values are passed out of band as positional arguments:
let shout (value: string) =
bash $"printf '%%s' {value} | tr '[:lower:]' '[:upper:]'"
shout: string -> ProcessCommandvalue: stringstringAn abbreviation for the CLI type . Basic Types
bash: FormattableString -> ProcessCommandBuilds a Bash program with interpolation values passed as positional arguments.
Requires & types
Requires: open Axial.Process.DSL (packages: Axial.Process)val shout: string -> ProcessCommandshout "it's $HOME" |> Process.run |> _.StdOut |> shouldEqual "IT'S $HOME"
shout: string -> ProcessCommand(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.Processrun: ^source -> ^resultRuns with live services and returns the value; raises ProcessRunException on failure.
_arg1: ProcessResultStdOut: stringshouldEqual: 'a -> 'a -> unitRequires & types
Requires: open Axial.Process (packages: Axial.Process)toFlow and the stream constructors are lazy. Capture helpers configure retention without executing;
routing helpers choose destinations independently. Process.run starts a command, spec, or Flow
and returns its value. A direct command captures stdout for the caller:
cmd $"printf hello" |> Process.run |> _.StdOut |> shouldEqual "hello"
cmd: FormattableString -> ProcessCommand(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.Processrun: ^source -> ^resultRuns with live services and returns the value; raises ProcessRunException on failure.
_arg1: ProcessResultStdOut: stringshouldEqual: 'a -> 'a -> unitRequires & types
Requires: open Axial.Process; open Axial.Process.DSL (packages: Axial.Process)Process.run raises ProcessRunException on failure. A successful command exposes its exit code:
cmd $"true" |> Process.run |> _.ExitCode |> shouldEqual 0
cmd: FormattableString -> ProcessCommand(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.Processrun: ^source -> ^resultRuns with live services and returns the value; raises ProcessRunException on failure.
_arg1: ProcessResultExitCode: intshouldEqual: 'a -> 'a -> unitRequires & types
Requires: open Axial.Process; open Axial.Process.DSL (packages: Axial.Process)Compose longer scripts inside flow { } and run them once. toFlow makes each command a lazy step:
let script : Flow<ProcessHostEnvironment, ProcessError, string> =
flow {
let! first = cmd $"printf first" |> toFlow
let! second = cmd $"printf second" |> toFlow
return first.StdOut + second.StdOut
}
script: Flow<ProcessHostEnvironment,ProcessError,string>Axial.Flow`3Axial.Process.ProcessHostEnvironmentAxial.Process.ProcessErrorExpected process errors. Runtime cancellation remains Cause.Interrupt.
stringAn abbreviation for the CLI type . Basic Types
flow: FlowBuilderThe universal flow { } computation expression.
first: ProcessResultcmd: FormattableString -> ProcessCommand(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
toFlow: ^a -> Flow<'b,ProcessError,ProcessResult>second: ProcessResultStdOut: string(+): ^T1 -> ^T2 -> ^T3Overloaded addition operator The first parameter. The second parameter. The result of the operation. 2 + 2 // Evaluates to 4 "Hello " + "World" // Evaluates to "Hello World"
Requires & types
Requires: open Axial; open Axial.Process; open Axial.Process.DSL (packages: Axial, Axial.Process)val script: Flow<ProcessHostEnvironment,ProcessError,string>script |> Process.run |> shouldEqual "firstsecond"
script: Flow<ProcessHostEnvironment,ProcessError,string>(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.Processrun: ^source -> ^resultRuns with live services and returns the value; raises ProcessRunException on failure.
shouldEqual: 'a -> 'a -> unitRequires & types
Requires: open Axial.Process (packages: Axial.Process)If a script needs to inspect a process failure rather than raise, Process.tryRun returns Exit.
An entry point can distinguish a failed stage from a startup error:
match shText "exit 3" |> Process.tryRun with
| Exit.Failure(Cause.Fail(ProcessError.StageFailed failure)) ->
shouldEqual 3 failure.Stage.ExitCode
| other -> failwithf "Expected stage failure, got %A" other
shText: string -> ProcessCommandBuilds an explicitly assembled POSIX shell program. Values in the text are not escaped by Axial.
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.ProcesstryRun: ^source -> ^resultRuns with live services and returns Exit, including typed failures and interruptions.
Axial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
FailureThe workflow failed due to a specific cause.
Axial.Cause`1Represents the cause of a failed workflow. The type of the domain-specific failure value.
FailAn expected domain-specific failure.
Axial.Process.ProcessErrorExpected process errors. Runtime cancellation remains Cause.Interrupt.
StageFailedfailure: StageFailureshouldEqual: 'a -> 'a -> unitExitCode: intStage: StageResultother: Exit<ProcessResult,ProcessError>failwithf: Printf.StringFormat<'T,'Result> -> 'TPrint to a string buffer and raise an exception with the given result. Helper printers must return strings. The formatter. The formatted result. See Printf.failwithf (link: ) for examples.
Requires & types
Requires: open Axial; open Axial.Process; open Axial.Process.DSL (packages: Axial, Axial.Process)The With variants accept an existing environment instead of supplying live services.
type AppEnvironment =
{ Process: IProcess
Console: IConsole
Region: string }
interface IHasProcess with member this.Process = this.Process
interface IHasConsole with member this.Console = this.Console
let reportingConsole = Console.test()
let appEnvironment =
{ Process = Process.live Clock.live FileSystem.live reportingConsole
Console = reportingConsole
Region = "eu" }
FsLiveDocsGeneratedPage4_99FDB6C21194.AppEnvironmentProcess: IProcessAxial.Process.IProcessExecutes lazily, awaiting each observation with backpressure.
Console: IConsoleAxial.Console.IConsoleProvides explicit access to standard console and terminal I/O.
Region: stringstringAn abbreviation for the CLI type . Basic Types
Axial.Process.IHasProcessthis: AppEnvironmentProcess: AppEnvironment -> unit -> IProcessAxial.Console.IHasConsoleDeclares that an environment supplies the console service. Implement this on the environment supplied at the host edge. A workflow that reads or writes the console constrains its environment with 'env :> IHasConsole.
Console: AppEnvironment -> unit -> IConsolereportingConsole: TestConsoleAxial.Console.ConsoleModuletest: unit -> TestConsoleCreates an in-memory console test double that captures output and reads scripted input.
appEnvironment: AppEnvironmentAxial.Process.Processlive: IClock -> IFileSystem -> IConsole -> IProcessAxial.PlatformService.ClockHelpers for the clock service.
live: IClockCreates a live clock backed by and a monotonic timer.
Axial.FileSystem.FileSystemModulelive: IFileSystemCreates a live file-system service backed by , , and .
Requires & types
Requires: open Axial.Console; open Axial.FileSystem; open Axial.PlatformService; open Axial.Process (packages: Axial.Console, Axial.FileSystem, Axial.PlatformService, Axial.Process)val reportingConsole: TestConsoleval appEnvironment: AppEnvironmentcmd $"dotnet --version"
|> Process.runWith appEnvironment
|> _.ExitCode
|> shouldEqual 0
cmd: FormattableString -> ProcessCommand(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Process.ProcessrunWith: 'env -> ^source -> ^resultRuns with supplied services and returns the value; raises ProcessRunException on failure.
appEnvironment: AppEnvironment_arg1: ProcessResultExitCode: intshouldEqual: 'a -> 'a -> unitRequires & types
Requires: open Axial.Process; open Axial.Process.DSL (packages: Axial.Process)For application composition, use Process.toFlow and run the enclosing workflow with Flow.run.
ProcessStream.runCollect returns values plus completion; a stream must have a terminal before a host runner
can execute it. Effectful terminals may have ProcessStreamError errors, which Process.tryRun supports; use the ordinary
Flow runner when the application wants its own exit-code policy.

