mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
cleanup
This commit is contained in:
parent
34759b7646
commit
eeed31837f
17 changed files with 47 additions and 288 deletions
|
@ -352,7 +352,6 @@ async fn process_line(readline: Result<String, ReadlineError>, 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,
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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)?;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -64,10 +64,10 @@ impl CommandRegistry {
|
|||
registry.insert(name.into(), command);
|
||||
}
|
||||
|
||||
crate fn names(&self) -> Vec<String> {
|
||||
let registry = self.registry.lock().unwrap();
|
||||
registry.keys().cloned().collect()
|
||||
}
|
||||
// crate fn names(&self) -> Vec<String> {
|
||||
// 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<OutputStream, ShellError> {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -486,15 +486,15 @@ impl Value {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn as_pair(&self) -> Result<(Tagged<Value>, Tagged<Value>), 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<Value>, Tagged<Value>), 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<String, ShellError> {
|
||||
match self {
|
||||
|
|
|
@ -239,7 +239,7 @@ fn view_text_value(value: &Tagged<Value>, source_map: &SourceMap) {
|
|||
}
|
||||
}
|
||||
//FIXME: this probably isn't correct
|
||||
SpanSource::Source(source) => None,
|
||||
SpanSource::Source(_source) => None,
|
||||
};
|
||||
|
||||
match extension {
|
||||
|
|
|
@ -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<String, Arc<dyn Command>>,
|
||||
}
|
||||
|
||||
pub struct CompletionPair {
|
||||
pub display: String,
|
||||
pub replacement: String,
|
||||
}
|
||||
|
||||
impl Into<completion::Pair> 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)
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue