API Reference › Builtin functions › arg_count
function

arg_count

arg_count() -> int

Returns how many command-line arguments the program received, including the program name at index 0. So a program run with no user arguments reports 1, and each added argument raises the count by one. Use it to validate that the required arguments were supplied and to bound the index you pass to arg. It takes no arguments and is the natural companion to arg when building command-line tools.

Example

program PrintAllArgs {
  handler ListArgs phase Start {
    print(arg_count())
    for index in 0 .. arg_count() {
      print(arg(index))
    }
  }
}
← All symbols