A bit more infra

This commit is contained in:
Yehuda Katz
2019-05-11 00:00:33 -07:00
parent e44d657424
commit 51e921b085
10 changed files with 116 additions and 12 deletions

21
src/commands/cd.rs Normal file
View File

@ -0,0 +1,21 @@
use crate::errors::ShellError;
use crate::object::process::Process;
use crate::object::{DirEntry, ShellObject, Value};
use derive_new::new;
use std::path::{Path, PathBuf};
use sysinfo::SystemExt;
#[derive(new)]
pub struct Cd;
impl crate::Command for Cd {
fn run(
&mut self,
args: Vec<String>,
_host: &dyn crate::Host,
env: &mut crate::Environment,
) -> Result<Value, ShellError> {
env.cwd = dunce::canonicalize(env.cwd().join(&args[0]).as_path())?;
Ok(Value::nothing())
}
}

View File

@ -4,6 +4,7 @@ use crate::object::Value;
pub trait Command {
fn run(
&mut self,
args: Vec<String>,
host: &dyn crate::Host,
env: &mut crate::Environment,
) -> Result<Value, ShellError>;

View File

@ -10,6 +10,7 @@ pub struct Ls;
impl crate::Command for Ls {
fn run(
&mut self,
_args: Vec<String>,
_host: &dyn crate::Host,
env: &mut crate::Environment,
) -> Result<Value, ShellError> {

View File

@ -12,6 +12,7 @@ pub struct Ps {
impl crate::Command for Ps {
fn run(
&mut self,
_args: Vec<String>,
_host: &dyn crate::Host,
_env: &mut crate::Environment,
) -> Result<Value, ShellError> {