Skip to main content

System utilities (sys)

Start here

bring sys gives your program access to command-line arguments, the current script directory, a timestamp helper, and exit. No extra native libraries or link flags are needed.

A tiny program

bring sys

println("Program: ", sys::getArg(0))
println("Script dir: ", sys::scriptDir())
println("Timestamp: ", sys::timestamp())
println("Arg count: ", sys::getArgCount())

Command-line arguments

Arguments are passed to your program after the -- separator on the compiler command line:

flowwing myapp.fg -- hello world 42

Inside your .fg:

bring sys

/; sys::getArg(0) is the program name
/; sys::getArg(1) is "hello"
/; sys::getArg(2) is "world"
/; sys::getArg(3) is "42"

var count: int = sys::getArgCount()
for (var i: int = 0 to count - 1 : 1) {
  println(i, ": ", sys::getArg(i))
}

Common operations

FunctionReturnsDescription
sys::getArgCount()intNumber of command-line arguments
sys::getArg(n)strThe nth argument (0 = program name)
sys::scriptDir()strDirectory of the running script
sys::timestamp()intCurrent Unix timestamp (seconds since epoch)
sys::exit(code)Terminates the program with exit code code

Early exit

bring sys

println("before")
sys::exit(42)
println("after")      /; this never runs

Source & tests (if you have the repository)

WhatWhere
Module sourcefw-modules/sys_module/sys-module.fg
Integration fixturestests/fixtures/LatestTests/SysModuleTests/