adding a builtin rm

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

@ -1,3 +1,29 @@
# clyde # clyde
A command-line shell for Windows. 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 /// prints environment variables
mod printenv; mod printenv;
/// removes files
mod rm;
/// the butt of a file /// the butt of a file
mod tail; mod tail;
@ -25,6 +28,7 @@ pub enum Builtin {
Changedir, Changedir,
Echo, Echo,
Printenv, Printenv,
Rm,
Tail, Tail,
Which, Which,
} }
@ -36,6 +40,7 @@ impl Builtin {
Changedir => &cd::Changedir, Changedir => &cd::Changedir,
Echo => &echo::Echo, Echo => &echo::Echo,
Printenv => &printenv::Printenv, Printenv => &printenv::Printenv,
Rm => &rm::Rm,
Tail => &tail::Tail, Tail => &tail::Tail,
Which => &which::Which, Which => &which::Which,
} }
@ -55,6 +60,7 @@ pub fn all() -> HashMap<&'static str, Builtin> {
("cd", Changedir), ("cd", Changedir),
("echo", Echo), ("echo", Echo),
("printenv", Printenv), ("printenv", Printenv),
("rm", Rm),
("tail", Tail), ("tail", Tail),
("which", Which), ("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}")] #[error("value type error: {0}")]
ValueTypeError(String), ValueTypeError(String),
#[error("error")] #[error("error: {0}")]
Misc(String), Misc(String),
} }

Loading…
Cancel
Save