mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 12:21:19 -03:00
builtin: propagate status from Rust builtins
The return type of `builtin_run_rust()` reflects that of C++ builtins.
This commit is contained in:
committed by
Johannes Altmanninger
parent
cfb5bb2505
commit
4b85c2f6db
@@ -23,7 +23,8 @@ fn rust_run_builtin(
|
||||
streams: Pin<&mut io_streams_t>,
|
||||
cpp_args: &Vec<wcharz_t>,
|
||||
builtin: RustBuiltin,
|
||||
);
|
||||
status_code: &mut i32,
|
||||
) -> bool;
|
||||
}
|
||||
|
||||
impl Vec<wcharz_t> {}
|
||||
@@ -79,7 +80,8 @@ fn rust_run_builtin(
|
||||
streams: Pin<&mut builtins_ffi::io_streams_t>,
|
||||
cpp_args: &Vec<wcharz_t>,
|
||||
builtin: RustBuiltin,
|
||||
) {
|
||||
status_code: &mut i32,
|
||||
) -> bool {
|
||||
let mut storage = Vec::<wchar::WString>::new();
|
||||
for arg in cpp_args {
|
||||
storage.push(arg.into());
|
||||
@@ -89,7 +91,14 @@ fn rust_run_builtin(
|
||||
args.push(arg.as_utfstr());
|
||||
}
|
||||
let streams = &mut io_streams_t::new(streams);
|
||||
run_builtin(parser.unpin(), streams, args.as_mut_slice(), builtin);
|
||||
|
||||
match run_builtin(parser.unpin(), streams, args.as_mut_slice(), builtin) {
|
||||
None => false,
|
||||
Some(status) => {
|
||||
*status_code = status;
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_builtin(
|
||||
|
||||
@@ -535,12 +535,18 @@ static maybe_t<RustBuiltin> try_get_rust_builtin(const wcstring &cmd) {
|
||||
return none();
|
||||
}
|
||||
|
||||
static proc_status_t builtin_run_rust(parser_t &parser, io_streams_t &streams,
|
||||
const wcstring_list_t &argv, RustBuiltin builtin) {
|
||||
static maybe_t<int> builtin_run_rust(parser_t &parser, io_streams_t &streams,
|
||||
const wcstring_list_t &argv, RustBuiltin builtin) {
|
||||
::rust::Vec<wcharz_t> rust_argv;
|
||||
for (const wcstring &arg : argv) {
|
||||
rust_argv.emplace_back(arg.c_str());
|
||||
}
|
||||
rust_run_builtin(parser, streams, rust_argv, builtin);
|
||||
return none();
|
||||
|
||||
int status_code;
|
||||
bool update_status = rust_run_builtin(parser, streams, rust_argv, builtin, status_code);
|
||||
if (update_status) {
|
||||
return status_code;
|
||||
} else {
|
||||
return none();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user