This commit is contained in:
Yehuda Katz
2019-05-17 18:24:13 -07:00
parent 52716d0c24
commit c30fc32b0c
5 changed files with 725 additions and 0 deletions

32
src/commands/bat.rs Normal file
View File

@@ -0,0 +1,32 @@
use crate::errors::ShellError;
use crate::prelude::*;
use derive_new::new;
use prettyprint::PrettyPrinter;
#[derive(new)]
pub struct Bat;
impl crate::Command for Bat {
fn run(&self, args: CommandArgs<'caller>) -> Result<VecDeque<ReturnValue>, ShellError> {
let target = match args.args.first() {
// TODO: This needs better infra
None => return Err(ShellError::string(format!("cat must take one arg"))),
Some(v) => v.as_string()?.clone(),
};
let cwd = args.env.cwd().to_path_buf();
let printer = PrettyPrinter::default()
.line_numbers(false)
.header(false)
.grid(false)
.build()
.map_err(|e| ShellError::string(e))?;
let file = cwd.join(target);
let _ = printer.file(file.display().to_string());
Ok(VecDeque::new())
}
}