adding a builtin rm

main
Jordan Orelli 9 months ago
parent 70e40cb7ae
commit 11a3911f28

@ -1,3 +1,29 @@
# clyde
A command-line shell for Windows.
## examples
In all examples, the Clyde prompt is written as follows:
```
```
1. Run a built-in command:
Built-in commands are invoked by executing them with a bare string
```
c:\dev\clyde ▷ cd src
c:\dev\clyde\src ▷
```
2. Run an external command:
External commands are invoked in the same way:
```
c:\one ▷ cd two
c:\one\two ▷
```

@ -7,6 +7,9 @@ mod echo;
/// prints environment variables
mod printenv;
/// removes files
mod rm;
/// the butt of a file
mod tail;
@ -25,6 +28,7 @@ pub enum Builtin {
Changedir,
Echo,
Printenv,
Rm,
Tail,
Which,
}
@ -36,6 +40,7 @@ impl Builtin {
Changedir => &cd::Changedir,
Echo => &echo::Echo,
Printenv => &printenv::Printenv,
Rm => &rm::Rm,
Tail => &tail::Tail,
Which => &which::Which,
}
@ -55,6 +60,7 @@ pub fn all() -> HashMap<&'static str, Builtin> {
("cd", Changedir),
("echo", Echo),
("printenv", Printenv),
("rm", Rm),
("tail", Tail),
("which", Which),
])

@ -0,0 +1,25 @@
use crate::{
error::ExecError,
run::{Call, Context, Value},
};
use std::fs;
pub struct Rm;
impl Call for Rm {
fn call(&self, _ctx: &mut Context, args: &[Value]) -> Result<Value, ExecError> {
match args.len() {
0 => {
todo!()
}
1 => {
let path = args[0].try_as_str()?;
fs::remove_file(path).map_err(|err| ExecError::Misc(err.to_string()))?;
}
_ => {
todo!()
}
}
Ok(Value::None)
}
}

@ -112,7 +112,7 @@ pub enum ExecError {
#[error("value type error: {0}")]
ValueTypeError(String),
#[error("error")]
#[error("error: {0}")]
Misc(String),
}

Loading…
Cancel
Save