ls and pwd
parent
d25382ee10
commit
e71c3f89f7
@ -0,0 +1,19 @@
|
||||
use crate::{
|
||||
error::ExecError,
|
||||
run::{Call, Context, Value},
|
||||
};
|
||||
use std::{env, fs, io::Write};
|
||||
|
||||
pub struct Ls;
|
||||
|
||||
impl Call for Ls {
|
||||
fn call(&self, ctx: &mut Context, args: &[Value]) -> Result<Value, ExecError> {
|
||||
let cwd = env::current_dir()?;
|
||||
let dir = fs::read_dir(&cwd)?;
|
||||
for child in dir {
|
||||
let child = child?;
|
||||
_ = write!(ctx.stdout, "{}\n", child.path().display());
|
||||
}
|
||||
Ok(Value::None)
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
use crate::{
|
||||
error::ExecError,
|
||||
run::{Call, Context, Value},
|
||||
};
|
||||
use std::{env, io::Write};
|
||||
|
||||
pub struct Pwd;
|
||||
|
||||
impl Call for Pwd {
|
||||
fn call(&self, ctx: &mut Context, args: &[Value]) -> Result<Value, ExecError> {
|
||||
let cwd = env::current_dir()?;
|
||||
_ = write!(ctx.stdout, "{}\n", cwd.display());
|
||||
Ok(Value::None)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue