2019-05-18 03:24:13 +02:00
|
|
|
use crate::errors::ShellError;
|
|
|
|
use crate::prelude::*;
|
|
|
|
use derive_new::new;
|
|
|
|
use prettyprint::PrettyPrinter;
|
|
|
|
|
|
|
|
#[derive(new)]
|
2019-05-18 16:15:22 +02:00
|
|
|
pub struct View;
|
2019-05-18 03:24:13 +02:00
|
|
|
|
2019-05-18 16:15:22 +02:00
|
|
|
impl crate::Command for View {
|
2019-05-18 03:24:13 +02:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|