Files
shed/src/builtin/source.rs
Kyler Clay 220f636ebd removed placeholder text in prompt
cd no longer panics if the given directory doesn't exist (wtf?)
2025-05-29 01:29:25 -04:00

38 lines
825 B
Rust

use crate::{jobs::JobBldr, libsh::error::{ShErr, ShErrKind, ShResult}, parse::{NdRule, Node}, prelude::*, state::{self, source_file}};
use super::setup_builtin;
pub fn source(node: Node, job: &mut JobBldr) -> ShResult<()> {
let NdRule::Command { assignments: _, argv } = node.class else {
unreachable!()
};
let (argv,_) = setup_builtin(argv, job, None)?;
for (arg,span) in argv {
let path = PathBuf::from(arg);
if !path.exists() {
return Err(
ShErr::full(
ShErrKind::ExecFail,
format!("source: File '{}' not found",path.display()),
span
)
);
}
if !path.is_file() {
return Err(
ShErr::full(
ShErrKind::ExecFail,
format!("source: Given path '{}' is not a file",path.display()),
span
)
);
}
source_file(path)?;
}
state::set_status(0);
Ok(())
}