mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 10:18:30 +02:00
All tests pass
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
use derive_new::new;
|
||||
use rustyline::completion::Completer;
|
||||
use rustyline::completion::{self, FilenameCompleter};
|
||||
use rustyline::line_buffer::LineBuffer;
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
use crate::commands::command::CallInfo;
|
||||
use crate::commands::command::{CallInfo, EvaluatedStaticCommandArgs};
|
||||
use crate::object::dir_entry_dict;
|
||||
use crate::prelude::*;
|
||||
use crate::shell::completer::{CompletionPair, NuCompleter};
|
||||
use crate::shell::completer::NuCompleter;
|
||||
use crate::shell::shell::Shell;
|
||||
use rustyline::completion::{Completer, FilenameCompleter};
|
||||
use rustyline::error::ReadlineError;
|
||||
use rustyline::completion::FilenameCompleter;
|
||||
use rustyline::hint::{Hinter, HistoryHinter};
|
||||
use std::path::{Path, PathBuf};
|
||||
pub struct FilesystemShell {
|
||||
@ -54,10 +53,10 @@ impl Shell for FilesystemShell {
|
||||
"filesystem".to_string()
|
||||
}
|
||||
|
||||
fn ls(&self, call_info: CallInfo, _input: InputStream) -> Result<OutputStream, ShellError> {
|
||||
fn ls(&self, args: EvaluatedStaticCommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let cwd = self.path.clone();
|
||||
let mut full_path = PathBuf::from(&self.path);
|
||||
match &call_info.args.nth(0) {
|
||||
match &args.nth(0) {
|
||||
Some(Tagged { item: value, .. }) => full_path.push(Path::new(&value.as_string()?)),
|
||||
_ => {}
|
||||
}
|
||||
@ -78,18 +77,15 @@ impl Shell for FilesystemShell {
|
||||
|
||||
let entries = match entries {
|
||||
Err(e) => {
|
||||
if let Some(s) = call_info.args.nth(0) {
|
||||
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(),
|
||||
call_info.name_span,
|
||||
));
|
||||
//FIXME
|
||||
return Err(ShellError::string(e.to_string()));
|
||||
}
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -101,7 +97,7 @@ impl Shell for FilesystemShell {
|
||||
let value = dir_entry_dict(
|
||||
filename,
|
||||
&entry.metadata()?,
|
||||
Tag::unknown_origin(call_info.name_span),
|
||||
Tag::unknown_origin(args.call_info.name_span),
|
||||
)?;
|
||||
shell_entries.push_back(ReturnSuccess::value(value))
|
||||
}
|
||||
@ -118,7 +114,7 @@ impl Shell for FilesystemShell {
|
||||
let value = dir_entry_dict(
|
||||
filename,
|
||||
&metadata,
|
||||
Tag::unknown_origin(call_info.name_span),
|
||||
Tag::unknown_origin(args.call_info.name_span),
|
||||
)?;
|
||||
shell_entries.push_back(ReturnSuccess::value(value))
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ use crate::parser::nom_input;
|
||||
use crate::parser::parse::token_tree::TokenNode;
|
||||
use crate::parser::parse::tokens::RawToken;
|
||||
use crate::parser::{Pipeline, PipelineElement};
|
||||
use crate::shell::completer::CompletionPair;
|
||||
use crate::shell::shell_manager::ShellManager;
|
||||
use crate::Tagged;
|
||||
use ansi_term::Color;
|
||||
|
@ -1,12 +1,10 @@
|
||||
use crate::commands::command::CallInfo;
|
||||
use crate::commands::command::{CallInfo, EvaluatedStaticCommandArgs};
|
||||
use crate::errors::ShellError;
|
||||
use crate::shell::completer::CompletionPair;
|
||||
use crate::stream::{InputStream, OutputStream};
|
||||
use rustyline::error::ReadlineError;
|
||||
|
||||
pub trait Shell {
|
||||
fn name(&self) -> String;
|
||||
fn ls(&self, call_info: CallInfo, input: InputStream) -> Result<OutputStream, ShellError>;
|
||||
fn ls(&self, args: EvaluatedStaticCommandArgs) -> Result<OutputStream, ShellError>;
|
||||
fn cd(&self, call_info: CallInfo, input: InputStream) -> Result<OutputStream, ShellError>;
|
||||
fn path(&self) -> String;
|
||||
fn set_path(&mut self, path: String);
|
||||
|
@ -1,11 +1,8 @@
|
||||
use crate::commands::command::CallInfo;
|
||||
use crate::commands::command::{CallInfo, EvaluatedStaticCommandArgs};
|
||||
use crate::errors::ShellError;
|
||||
use crate::shell::completer::CompletionPair;
|
||||
use crate::shell::filesystem_shell::FilesystemShell;
|
||||
use crate::shell::shell::Shell;
|
||||
use crate::stream::{InputStream, OutputStream};
|
||||
use rustyline::completion::Completer;
|
||||
use rustyline::error::ReadlineError;
|
||||
use std::error::Error;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@ -88,10 +85,10 @@ impl ShellManager {
|
||||
self.set_path(self.path());
|
||||
}
|
||||
|
||||
pub fn ls(&self, call_info: CallInfo, input: InputStream) -> Result<OutputStream, ShellError> {
|
||||
pub fn ls(&self, args: EvaluatedStaticCommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let env = self.shells.lock().unwrap();
|
||||
|
||||
env.last().unwrap().ls(call_info, input)
|
||||
env.last().unwrap().ls(args)
|
||||
}
|
||||
pub fn cd(&self, call_info: CallInfo, input: InputStream) -> Result<OutputStream, ShellError> {
|
||||
let env = self.shells.lock().unwrap();
|
||||
|
@ -1,8 +1,6 @@
|
||||
use crate::commands::command::CallInfo;
|
||||
use crate::commands::command::{CallInfo, EvaluatedStaticCommandArgs};
|
||||
use crate::prelude::*;
|
||||
use crate::shell::completer::CompletionPair;
|
||||
use crate::shell::shell::Shell;
|
||||
use rustyline::error::ReadlineError;
|
||||
use std::ffi::OsStr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@ -59,7 +57,7 @@ impl Shell for ValueShell {
|
||||
"value".to_string()
|
||||
}
|
||||
|
||||
fn ls(&self, _call_info: CallInfo, _input: InputStream) -> Result<OutputStream, ShellError> {
|
||||
fn ls(&self, _args: EvaluatedStaticCommandArgs) -> Result<OutputStream, ShellError> {
|
||||
Ok(self
|
||||
.members()
|
||||
.map(|x| ReturnSuccess::value(x))
|
||||
|
Reference in New Issue
Block a user