diff --git a/src/cli.rs b/src/cli.rs index 250fd49186..ff0deae11a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -352,7 +352,6 @@ async fn process_line(readline: Result, ctx: &mut Context .push(ClassifiedCommand::Internal(InternalCommand { command: static_command(autoview::Autoview), name_span: Span::unknown(), - source_map: ctx.source_map.clone(), args: hir::Call::new( Box::new(hir::Expression::synthetic_string("autoview")), None, @@ -489,7 +488,6 @@ fn classify_command( Ok(ClassifiedCommand::Internal(InternalCommand { command, name_span: head.span().clone(), - source_map: context.source_map.clone(), args, })) } diff --git a/src/commands/cd.rs b/src/commands/cd.rs index a66f019ce8..0fe24add87 100644 --- a/src/commands/cd.rs +++ b/src/commands/cd.rs @@ -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>, -// } - -// 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 { -// args.process(registry, cd)?.run() -// // cd(args, registry) -// } -// } - -// pub fn cd(CdArgs { target }: CdArgs, context: RunnableContext) -> Result { -// 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 { -// // args.shell_manager.cd(args.call_info, args.input) -// } pub fn cd(args: CommandArgs, registry: &CommandRegistry) -> Result { let shell_manager = args.shell_manager.clone(); diff --git a/src/commands/classified.rs b/src/commands/classified.rs index ad00727c83..cb02b674c2 100644 --- a/src/commands/classified.rs +++ b/src/commands/classified.rs @@ -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, crate name_span: Span, - crate source_map: SourceMap, crate args: hir::Call, } diff --git a/src/commands/ls.rs b/src/commands/ls.rs index c8e9b20847..7a101d3d5c 100644 --- a/src/commands/ls.rs +++ b/src/commands/ls.rs @@ -1,54 +1,6 @@ use crate::errors::ShellError; use crate::prelude::*; -//pub fn ls(args: CommandArgs, registry: &CommandRegistry) -> Result { -// 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 { let shell_manager = args.shell_manager.clone(); let args = args.evaluate_once(registry)?; diff --git a/src/commands/open.rs b/src/commands/open.rs index 97308c0479..4f6edf35f3 100644 --- a/src/commands/open.rs +++ b/src/commands/open.rs @@ -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, --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, diff --git a/src/commands/plugin.rs b/src/commands/plugin.rs index 9d597a859d..41b8a83c65 100644 --- a/src/commands/plugin.rs +++ b/src/commands/plugin.rs @@ -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::(&input); - match response { - Ok(NuResult::response { params }) => match params { - Ok(_) => {} - Err(e) => { - return Err(e); - */ let mut bos: VecDeque> = VecDeque::new(); bos.push_back(Value::Primitive(Primitive::BeginningOfStream).tagged_unknown()); diff --git a/src/commands/reject.rs b/src/commands/reject.rs index f90f60b129..443e6e3726 100644 --- a/src/commands/reject.rs +++ b/src/commands/reject.rs @@ -3,7 +3,6 @@ use crate::object::base::reject_fields; use crate::prelude::*; pub fn reject(args: CommandArgs, registry: &CommandRegistry) -> Result { - let name_span = args.name_span(); let args = args.evaluate_once(registry)?; let len = args.len(); let span = args.name_span(); diff --git a/src/commands/rm.rs b/src/commands/rm.rs index 8f2fd46aa6..c50ffd9527 100644 --- a/src/commands/rm.rs +++ b/src/commands/rm.rs @@ -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"); diff --git a/src/commands/save.rs b/src/commands/save.rs index 9fd78c6db9..aa32811b15 100644 --- a/src/commands/save.rs +++ b/src/commands/save.rs @@ -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() { diff --git a/src/context.rs b/src/context.rs index 1f7d405c59..b7fd149311 100644 --- a/src/context.rs +++ b/src/context.rs @@ -64,10 +64,10 @@ impl CommandRegistry { registry.insert(name.into(), command); } - crate fn names(&self) -> Vec { - let registry = self.registry.lock().unwrap(); - registry.keys().cloned().collect() - } + // crate fn names(&self) -> Vec { + // let registry = self.registry.lock().unwrap(); + // registry.keys().cloned().collect() + // } } #[derive(Clone)] @@ -102,9 +102,9 @@ impl Context { self.source_map.insert(uuid, span_source); } - pub fn clone_commands(&self) -> CommandRegistry { - self.registry.clone() - } + // pub fn clone_commands(&self) -> CommandRegistry { + // self.registry.clone() + // } crate fn has_command(&self, name: &str) -> bool { self.registry.has(name) @@ -124,19 +124,6 @@ impl Context { input: InputStream, ) -> Result { let command_args = self.command_args(args, input, source, source_map, name_span); - /* - let command_args = CommandArgs { - host: self.host.clone(), - shell_manager: self.shell_manager.clone(), - call_info: CallInfo { - name_span, - source_map, - args, - }, - input, - }; - */ - command.run(command_args, self.registry()).await } diff --git a/src/object/base.rs b/src/object/base.rs index 70683f8fe2..2da89c1810 100644 --- a/src/object/base.rs +++ b/src/object/base.rs @@ -486,15 +486,15 @@ impl Value { } } - crate fn as_pair(&self) -> Result<(Tagged, Tagged), ShellError> { - match self { - Value::List(list) if list.len() == 2 => Ok((list[0].clone(), list[1].clone())), - other => Err(ShellError::string(format!( - "Expected pair, got {:?}", - other - ))), - } - } + // crate fn as_pair(&self) -> Result<(Tagged, Tagged), ShellError> { + // match self { + // Value::List(list) if list.len() == 2 => Ok((list[0].clone(), list[1].clone())), + // other => Err(ShellError::string(format!( + // "Expected pair, got {:?}", + // other + // ))), + // } + // } crate fn as_string(&self) -> Result { match self { diff --git a/src/plugins/textview.rs b/src/plugins/textview.rs index ce7f50eec3..cd44ed12ae 100644 --- a/src/plugins/textview.rs +++ b/src/plugins/textview.rs @@ -239,7 +239,7 @@ fn view_text_value(value: &Tagged, source_map: &SourceMap) { } } //FIXME: this probably isn't correct - SpanSource::Source(source) => None, + SpanSource::Source(_source) => None, }; match extension { diff --git a/src/shell/completer.rs b/src/shell/completer.rs index df64067c11..4e53f41721 100644 --- a/src/shell/completer.rs +++ b/src/shell/completer.rs @@ -1,6 +1,5 @@ use derive_new::new; -use rustyline::completion::{self, Completer, FilenameCompleter}; -use rustyline::line_buffer::LineBuffer; +use rustyline::completion::{Completer, FilenameCompleter}; #[derive(new)] crate struct NuCompleter { @@ -8,20 +7,6 @@ crate struct NuCompleter { //pub commands: indexmap::IndexMap>, } -pub struct CompletionPair { - pub display: String, - pub replacement: String, -} - -impl Into for CompletionPair { - fn into(self) -> completion::Pair { - completion::Pair { - display: self.display, - replacement: self.replacement, - } - } -} - impl NuCompleter { pub fn complete( &self, @@ -89,8 +74,8 @@ impl NuCompleter { Ok((replace_pos, completions)) } - fn update(&self, line: &mut LineBuffer, start: usize, elected: &str) { - let end = line.pos(); - line.replace(start..end, elected) - } + // fn update(&self, line: &mut LineBuffer, start: usize, elected: &str) { + // let end = line.pos(); + // line.replace(start..end, elected) + // } } diff --git a/src/shell/filesystem_shell.rs b/src/shell/filesystem_shell.rs index f0e45f55b9..142af2d7f2 100644 --- a/src/shell/filesystem_shell.rs +++ b/src/shell/filesystem_shell.rs @@ -1,4 +1,4 @@ -use crate::commands::command::{CallInfo, EvaluatedStaticCommandArgs}; +use crate::commands::command::EvaluatedStaticCommandArgs; use crate::object::dir_entry_dict; use crate::prelude::*; use crate::shell::completer::NuCompleter; diff --git a/src/shell/shell.rs b/src/shell/shell.rs index 09869968f2..fd0b5ed5c3 100644 --- a/src/shell/shell.rs +++ b/src/shell/shell.rs @@ -1,6 +1,6 @@ -use crate::commands::command::{CallInfo, EvaluatedStaticCommandArgs}; +use crate::commands::command::EvaluatedStaticCommandArgs; use crate::errors::ShellError; -use crate::stream::{InputStream, OutputStream}; +use crate::stream::OutputStream; pub trait Shell { fn name(&self) -> String; diff --git a/src/shell/shell_manager.rs b/src/shell/shell_manager.rs index e93a2d61fa..f43ef7c9c4 100644 --- a/src/shell/shell_manager.rs +++ b/src/shell/shell_manager.rs @@ -1,8 +1,8 @@ -use crate::commands::command::{CallInfo, EvaluatedStaticCommandArgs}; +use crate::commands::command::EvaluatedStaticCommandArgs; use crate::errors::ShellError; use crate::shell::filesystem_shell::FilesystemShell; use crate::shell::shell::Shell; -use crate::stream::{InputStream, OutputStream}; +use crate::stream::OutputStream; use std::error::Error; use std::sync::{Arc, Mutex}; diff --git a/src/shell/value_shell.rs b/src/shell/value_shell.rs index 9443753717..34bb5c291b 100644 --- a/src/shell/value_shell.rs +++ b/src/shell/value_shell.rs @@ -1,4 +1,4 @@ -use crate::commands::command::{CallInfo, EvaluatedStaticCommandArgs}; +use crate::commands::command::EvaluatedStaticCommandArgs; use crate::prelude::*; use crate::shell::shell::Shell; use std::ffi::OsStr;