Entry points
Where a Faber program starts.
The ordinary entry point#
main — "it begins". No parameters, no return type.
faber convert --to en — English reader surfacemain {
print "Salve, munde!"
}faber convert --to la — canonical Faberincipit {
nota "Salve, munde!"
}faber convert --to th-TH — Thaiเริ่ม {
บันทึก "Salve, munde!"
}faber convert --to zh-Hans — Simplified Chinese入口 {
显示 "Salve, munde!"
}faber convert --to zh-Hant — Traditional Chinese入口 {
註記 "Salve, munde!"
}faber convert --to vi — Vietnamesebắt_đầu {
ghi_chú "Salve, munde!"
}faber convert --to ar — Arabicبداية {
اعرض "Salve, munde!"
}faber convert --to hi — Hindiआरंभ {
दिखाओ "Salve, munde!"
}Async entry point#
async_main — "it will begin". Use it when the program awaits anything.
faber convert --to en — English reader surfaceasync_main {
print "async ready"
}faber convert --to la — canonical Faberincipiet {
nota "async ready"
}faber convert --to th-TH — Thaiเริ่มอะซิงก์ {
บันทึก "async ready"
}faber convert --to zh-Hans — Simplified Chinese异步入口 {
显示 "async ready"
}faber convert --to zh-Hant — Traditional Chinese非同步入口 {
註記 "async ready"
}faber convert --to vi — Vietnamesebắt_đầu_bất_đồng_bộ {
ghi_chú "async ready"
}faber convert --to ar — Arabicاستهلال {
اعرض "async ready"
}faber convert --to hi — Hindiआरंभasync {
दिखाओ "async ready"
}The two are alternatives, not a pair: a program declares one or the other.
Exit code#
exit (en exit) after the entry sets the process exit code. The body runs
to its end first and keeps its output; the code is only the status the process
returns, so exit 3 does not stop the body early. faber run ends with that
code, and so does the program built for any target that runs programs: the
runner, Rust, Go, TypeScript, Swift, Python, LLVM and Cranelift all end with
the status the entry names. A plain entry ends with 0.
Since 1.19 the code must be in the POSIX range 0 to 255. A constant outside it
is refused (SEM010 main_exit_out_of_range), and a run-time value outside it
traps, on the runner and every target alike.
faber convert --to en — English reader surfacemain exit 2 {
print "done"
}faber convert --to la — canonical Faberincipit exitus 2 {
nota "done"
}faber convert --to th-TH — Thaiเริ่ม ทางออก 2 {
บันทึก "done"
}faber convert --to zh-Hans — Simplified Chinese入口 退出 2 {
显示 "done"
}faber convert --to zh-Hant — Traditional Chinese入口 出口 2 {
註記 "done"
}faber convert --to vi — Vietnamesebắt_đầu thoát 2 {
ghi_chú "done"
}faber convert --to ar — Arabicبداية مخرج 2 {
اعرض "done"
}faber convert --to hi — Hindiआरंभ निर्गम 2 {
दिखाओ "done"
}Command-line arguments#
args binds the parsed argument object.
faber convert --to en — English reader surfacemain args args {
print "started"
}faber convert --to la — canonical Faberincipit argumenta args {
nota "started"
}faber convert --to th-TH — Thaiเริ่ม อาร์กิวเมนต์ args {
บันทึก "started"
}faber convert --to zh-Hans — Simplified Chinese入口 参数 args {
显示 "started"
}faber convert --to zh-Hant — Traditional Chinese入口 引數 args {
註記 "started"
}faber convert --to vi — Vietnamesebắt_đầu đối_số args {
ghi_chú "started"
}faber convert --to ar — Arabicبداية وسائط args {
اعرض "started"
}faber convert --to hi — Hindiआरंभ तर्क args {
दिखाओ "started"
}Naming the command#
The @ cli annotation names the binary the package produces.
faber convert --to en — English reader surface@ cli { name = "salve" }
main args args {
print "started"
}faber convert --to la — canonical Faber@ cli { nomen = "salve" }
incipit argumenta args {
nota "started"
}faber convert --to th-TH — Thai@ cli { ชื่อ = "salve" }
เริ่ม อาร์กิวเมนต์ args {
บันทึก "started"
}faber convert --to zh-Hans — Simplified Chinese@ 命令行 { 名称 = "salve" }
入口 参数 args {
显示 "started"
}faber convert --to zh-Hant — Traditional Chinese@ 命令行 { 名稱 = "salve" }
入口 引數 args {
註記 "started"
}faber convert --to vi — Vietnamese@ cli { tên = "salve" }
bắt_đầu đối_số args {
ghi_chú "started"
}faber convert --to ar — Arabic@ cli { اسم = "salve" }
بداية وسائط args {
اعرض "started"
}faber convert --to hi — Hindi@ cli { नाम = "salve" }
आरंभ तर्क args {
दिखाओ "started"
}Declaring options#
@ option declares one command-line option. Repeat it for each. The binding
name comes first, then keyword-introduced fields — no braces, no commas.
@ cli { name = "salve" }
@ option { binding = name, short = "n", long = "nomen", type = string, description = "who to greet" }
@ option { binding = quotiens, long = "quotiens", type = int, description = "how many times" }
main args args {
print "started"
}| Field | Purpose |
|---|---|
| (first word) | The name the parsed value binds to |
short | Short flag, as in -n |
long | Long flag, as in --nomen |
type | The option's type |
description | Help text |
global | Accept the option on every subcommand |
An option can declare long without short, as quotiens does above.
Related: Commands for running what you build, and A program is a package for the surrounding package layout.