Improved error reporting and fully implemented the shopt command
This commit is contained in:
@@ -12,8 +12,9 @@ pub mod jobctl;
|
||||
pub mod alias;
|
||||
pub mod flowctl;
|
||||
pub mod zoltraak;
|
||||
pub mod shopt;
|
||||
|
||||
pub const BUILTINS: [&str;15] = [
|
||||
pub const BUILTINS: [&str;16] = [
|
||||
"echo",
|
||||
"cd",
|
||||
"export",
|
||||
@@ -28,7 +29,8 @@ pub const BUILTINS: [&str;15] = [
|
||||
"break",
|
||||
"continue",
|
||||
"exit",
|
||||
"zoltraak"
|
||||
"zoltraak",
|
||||
"shopt"
|
||||
];
|
||||
|
||||
/// Sets up a builtin command
|
||||
|
||||
30
src/builtin/shopt.rs
Normal file
30
src/builtin/shopt.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use crate::{jobs::JobBldr, libsh::error::{ShResult, ShResultExt}, parse::{NdRule, Node}, prelude::*, procio::{borrow_fd, IoStack}, state::write_shopts};
|
||||
|
||||
use super::setup_builtin;
|
||||
|
||||
pub fn shopt(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -> ShResult<()> {
|
||||
let NdRule::Command { assignments: _, argv } = node.class else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
let (argv,io_frame) = setup_builtin(argv, job, Some((io_stack,node.redirs)))?;
|
||||
|
||||
let mut io_frame = io_frame.unwrap();
|
||||
io_frame.redirect()?;
|
||||
for (arg,span) in argv {
|
||||
let Some(mut output) = write_shopts(|s| s.query(&arg)).blame(span)? else {
|
||||
continue
|
||||
};
|
||||
|
||||
let output_channel = borrow_fd(STDOUT_FILENO);
|
||||
output.push('\n');
|
||||
|
||||
if let Err(e) = write(output_channel, output.as_bytes()) {
|
||||
io_frame.restore()?;
|
||||
return Err(e.into())
|
||||
}
|
||||
}
|
||||
io_frame.restore()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -61,6 +61,7 @@ pub fn zoltraak(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -> ShResu
|
||||
match flag {
|
||||
'r' => flags |= ZoltFlags::RECURSIVE,
|
||||
'f' => flags |= ZoltFlags::FORCE,
|
||||
'v' => flags |= ZoltFlags::VERBOSE,
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
@@ -141,7 +142,7 @@ fn annihilate(path: &str, flags: ZoltFlags) -> ShResult<()> {
|
||||
fs::remove_file(path)?;
|
||||
if is_verbose {
|
||||
let stderr = borrow_fd(STDERR_FILENO);
|
||||
write(stderr, format!("removed file '{path}'").as_bytes())?;
|
||||
write(stderr, format!("shredded file '{path}'\n").as_bytes())?;
|
||||
}
|
||||
|
||||
} else if path_buf.is_dir() {
|
||||
@@ -183,7 +184,7 @@ fn annihilate_recursive(dir: &str, flags: ZoltFlags) -> ShResult<()> {
|
||||
fs::remove_dir(dir)?;
|
||||
if is_verbose {
|
||||
let stderr = borrow_fd(STDERR_FILENO);
|
||||
write(stderr, format!("removed directory '{dir}'").as_bytes())?;
|
||||
write(stderr, format!("shredded directory '{dir}'\n").as_bytes())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user