Summary
Add a process.exit(code: int) function to the process module that terminates the program with the specified exit code.
Use Case
When writing CLI tools in Bishop (like gh-clank.b in auto-mirror), we need to:
- Exit with a specific exit code to indicate success/failure to the calling shell
- Propagate exit codes from child processes
Currently there's no way to exit with a non-zero exit code. The generated main() always returns 0:
int main(int argc, char* argv[]) {
process::init_args(argc, argv);
bishop::rt::run(_bishop_main);
return 0; // Always 0!
}
Proposed API
import process;
fn main() {
// ... do work ...
if error_occurred {
process.exit(1); // Exit with code 1
}
// Or propagate child exit code
result := process.run("some-command", []) or {
process.exit(1);
};
if !result.success {
process.exit(result.exit_code);
}
}
Implementation Notes
The function should call std::exit(code) or _exit(code) in the runtime. Since this terminates the process immediately, it doesn't need to return a value.
Related
This is blocking issue chrishayen/auto-mirror#57 (gh-clank.sh equivalent).
Summary
Add a
process.exit(code: int)function to the process module that terminates the program with the specified exit code.Use Case
When writing CLI tools in Bishop (like
gh-clank.bin auto-mirror), we need to:Currently there's no way to exit with a non-zero exit code. The generated
main()always returns 0:Proposed API
Implementation Notes
The function should call
std::exit(code)or_exit(code)in the runtime. Since this terminates the process immediately, it doesn't need to return a value.Related
This is blocking issue chrishayen/auto-mirror#57 (gh-clank.sh equivalent).