Skip to content

Add process.exit(code) function #153

Description

@clank-hayen

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:

  1. Exit with a specific exit code to indicate success/failure to the calling shell
  2. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions