This commit is contained in:
Jonathan Turner
2019-08-10 08:49:43 +12:00
parent 34759b7646
commit eeed31837f
17 changed files with 47 additions and 288 deletions

View File

@@ -1,89 +1,5 @@
use crate::commands::StaticCommand;
use crate::errors::ShellError;
use crate::prelude::*;
use std::env;
use std::path::PathBuf;
// pub struct Cd;
// #[derive(Deserialize)]
// pub struct CdArgs {
// target: Option<Tagged<PathBuf>>,
// }
// impl StaticCommand for Cd {
// fn name(&self) -> &str {
// "cd"
// }
// fn signature(&self) -> Signature {
// Signature::build("cd")
// .optional("target", SyntaxType::Path)
// .filter()
// }
// fn run(
// &self,
// args: CommandArgs,
// registry: &CommandRegistry,
// ) -> Result<OutputStream, ShellError> {
// args.process(registry, cd)?.run()
// // cd(args, registry)
// }
// }
// pub fn cd(CdArgs { target }: CdArgs, context: RunnableContext) -> Result<OutputStream, ShellError> {
// let cwd = context.cwd().to_path_buf();
// let path = match &target {
// None => match dirs::home_dir() {
// Some(o) => o,
// _ => {
// return Err(ShellError::labeled_error(
// "Can not change to home directory",
// "can not go to home",
// context.name,
// ))
// }
// },
// Some(v) => {
// // let target = v.item.as_string()?;
// match dunce::canonicalize(cwd.join(&v.item()).as_path()) {
// Ok(p) => p,
// Err(_) => {
// return Err(ShellError::labeled_error(
// "Can not change to directory",
// "directory not found",
// v.span(),
// ));
// }
// }
// }
// };
// let mut stream = VecDeque::new();
// match env::set_current_dir(&path) {
// Ok(_) => {}
// Err(_) => {
// if let Some(path) = target {
// return Err(ShellError::labeled_error(
// "Can not change to directory",
// "directory not found",
// path.span(),
// ));
// } else {
// return Err(ShellError::string("Can not change to directory"));
// }
// }
// }
// stream.push_back(ReturnSuccess::change_cwd(
// path.to_string_lossy().to_string(),
// ));
// Ok(stream.into())
// // pub fn cd(args: CommandArgs) -> Result<OutputStream, ShellError> {
// // args.shell_manager.cd(args.call_info, args.input)
// }
pub fn cd(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let shell_manager = args.shell_manager.clone();

View File

@@ -1,5 +1,4 @@
use crate::commands::Command;
use crate::context::SourceMap;
use crate::parser::{hir, TokenNode};
use crate::prelude::*;
use bytes::{BufMut, BytesMut};
@@ -99,7 +98,6 @@ impl ClassifiedCommand {
crate struct InternalCommand {
crate command: Arc<Command>,
crate name_span: Span,
crate source_map: SourceMap,
crate args: hir::Call,
}

View File

@@ -1,54 +1,6 @@
use crate::errors::ShellError;
use crate::prelude::*;
//pub fn ls(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
// let args = args.evaluate_once(registry)?;
// let path = PathBuf::from(args.shell_manager.path());
// let mut full_path = PathBuf::from(path);
// match &args.nth(0) {
// Some(Tagged {
// item: Value::Primitive(Primitive::String(s)),
// ..
// }) => full_path.push(Path::new(&s)),
// _ => {}
// }
// let entries = std::fs::read_dir(&full_path);
// let entries = match entries {
// Err(e) => {
// if let Some(s) = args.nth(0) {
// return Err(ShellError::labeled_error(
// e.to_string(),
// e.to_string(),
// s.span(),
// ));
// } else {
// return Err(ShellError::labeled_error(
// e.to_string(),
// e.to_string(),
// args.name_span(),
// ));
// }
// }
// Ok(o) => o,
// };
// let mut shell_entries = VecDeque::new();
// for entry in entries {
// let entry = entry?;
// let filepath = entry.path();
// let filename = filepath.strip_prefix(&full_path).unwrap();
// let value = dir_entry_dict(
// filename,
// &entry.metadata()?,
// Tag::unknown_origin(args.call_info.name_span),
// )?;
// shell_entries.push_back(ReturnSuccess::value(value))
// }
// Ok(shell_entries.to_output_stream())
pub fn ls(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let shell_manager = args.shell_manager.clone();
let args = args.evaluate_once(registry)?;

View File

@@ -25,7 +25,7 @@ impl StaticCommand for Open {
fn signature(&self) -> Signature {
Signature::build(self.name())
.required("path", SyntaxType::Block)
.required("path", SyntaxType::Path)
.switch("raw")
}
@@ -92,62 +92,6 @@ fn run(
Ok(stream.boxed().to_output_stream())
}
// command! {
// Open as open(args, path: Spanned<PathBuf>, --raw: Switch,) {
// let span = args.name_span();
// let env = args.env.clone();
// let path = env
// .lock()
// .unwrap()
// .path()
// .to_path_buf();
// let full_path = PathBuf::from(cwd);
// let path_str = path.to_str().ok_or(ShellError::type_error("Path", "invalid path".spanned(path.span)))?;
// let (file_extension, contents, contents_span, span_source) = fetch(&full_path, path_str, path.span)?;
// let file_extension = if raw.is_present() {
// None
// } else {
// file_extension
// };
// let mut stream = VecDeque::new();
// if let Some(uuid) = contents_span.source {
// // If we have loaded something, track its source
// stream.push_back(ReturnSuccess::action(CommandAction::AddSpanSource(uuid, span_source)))
// }
// match contents {
// Value::Primitive(Primitive::String(string)) => {
// let value = parse_as_value(
// file_extension,
// string,
// contents_span,
// span,
// )?;
// match value {
// Spanned { item: Value::List(list), .. } => {
// for elem in list {
// stream.push_back(ReturnSuccess::value(elem));
// }
// }
// x => stream.push_back(ReturnSuccess::value(x))
// }
// },
// other => stream.push_back(ReturnSuccess::value(other.spanned(contents_span))),
// };
// stream
// }
// }
pub fn fetch(
cwd: &PathBuf,
location: &str,

View File

@@ -72,26 +72,6 @@ pub fn filter_plugin(
.spawn()
.expect("Failed to spawn child process");
/*
{
let stdin = child.stdin.as_mut().expect("Failed to open stdin");
let stdout = child.stdout.as_mut().expect("Failed to open stdout");
let mut reader = BufReader::new(stdout);
let request = JsonRpc::new("begin_filter", args.args.call_info);
let request_raw = serde_json::to_string(&request).unwrap();
stdin.write(format!("{}\n", request_raw).as_bytes())?;
let mut input = String::new();
match reader.read_line(&mut input) {
Ok(_) => {
let response = serde_json::from_str::<NuResult>(&input);
match response {
Ok(NuResult::response { params }) => match params {
Ok(_) => {}
Err(e) => {
return Err(e);
*/
let mut bos: VecDeque<Tagged<Value>> = VecDeque::new();
bos.push_back(Value::Primitive(Primitive::BeginningOfStream).tagged_unknown());

View File

@@ -3,7 +3,6 @@ use crate::object::base::reject_fields;
use crate::prelude::*;
pub fn reject(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let name_span = args.name_span();
let args = args.evaluate_once(registry)?;
let len = args.len();
let span = args.name_span();

View File

@@ -58,10 +58,10 @@ pub fn rm(
Ok(path) => {
if path.is_dir() {
if !recursive {
return Err(ShellError::string(
return Err(ShellError::labeled_error(
"is a directory",
// "is a directory",
// args.call_info.name_span,
"is a directory",
context.name,
));
}
std::fs::remove_dir_all(&path).expect("can not remove directory");

View File

@@ -58,27 +58,27 @@ pub fn save(
full_path.push(Path::new(file));
}
_ => {
// yield Err(ShellError::labeled_error(
// "Save requires a filepath",
// "needs path",
// context.name,
// ));
yield Err(ShellError::labeled_error(
"Save requires a filepath",
"needs path",
context.name,
));
}
},
None => {
// yield Err(ShellError::labeled_error(
// "Save requires a filepath",
// "needs path",
// context.name,
// ));
yield Err(ShellError::labeled_error(
"Save requires a filepath",
"needs path",
context.name,
));
}
}
} else {
// yield Err(ShellError::labeled_error(
// "Save requires a filepath",
// "needs path",
// context.name,
// ));
yield Err(ShellError::labeled_error(
"Save requires a filepath",
"needs path",
context.name,
));
}
let contents = match full_path.extension() {