Function uucore::error::set_exit_code[][src]

pub fn set_exit_code(code: i32)
Expand description

Set the exit code for the program if uumain returns Ok(()).

This function is most useful for non-fatal errors, for example when applying an operation to multiple files:

use uucore::error::{UResult, set_exit_code};

fn uumain(args: impl uucore::Args) -> UResult<()> {
    ...
    for file in files {
        let res = some_operation_that_might_fail(file);
        match res {
            Ok() => {},
            Err(_) => set_exit_code(1),
        }
    }
    Ok(()) // If any of the operations failed, 1 is returned.
}