nushell/src/commands/view.rs

27 lines
731 B
Rust
Raw Normal View History

2019-05-18 03:24:13 +02:00
use crate::errors::ShellError;
use crate::prelude::*;
use prettyprint::PrettyPrinter;
2019-05-22 09:12:03 +02:00
pub fn view(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(),
};
2019-05-18 03:24:13 +02:00
2019-05-22 09:12:03 +02:00
let cwd = args.env.cwd().to_path_buf();
2019-05-18 03:24:13 +02:00
2019-05-22 09:12:03 +02:00
let printer = PrettyPrinter::default()
.line_numbers(false)
.header(false)
.grid(false)
.build()
.map_err(|e| ShellError::string(e))?;
2019-05-18 03:24:13 +02:00
2019-05-22 09:12:03 +02:00
let file = cwd.join(target);
2019-05-18 03:24:13 +02:00
2019-05-22 09:12:03 +02:00
let _ = printer.file(file.display().to_string());
2019-05-18 03:24:13 +02:00
2019-05-22 09:12:03 +02:00
Ok(VecDeque::new())
2019-05-18 03:24:13 +02:00
}