mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 12:17:51 +02:00
Remove dead code
This commit is contained in:
@ -1,9 +1,6 @@
|
||||
use crate::object::Value;
|
||||
use crate::ShellError;
|
||||
use derive_new::new;
|
||||
use std::cell::Cell;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(Debug)]
|
||||
pub enum LogLevel {
|
||||
Trace,
|
||||
@ -14,81 +11,9 @@ pub enum LogLevel {
|
||||
Fatal,
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(Debug)]
|
||||
pub struct LogItem {
|
||||
level: LogLevel,
|
||||
value: Value,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ObjectStream<T> {
|
||||
queue: VecDeque<T>,
|
||||
}
|
||||
|
||||
impl<T> ObjectStream<T> {
|
||||
crate fn empty() -> ObjectStream<T> {
|
||||
ObjectStream {
|
||||
queue: VecDeque::new(),
|
||||
}
|
||||
}
|
||||
|
||||
crate fn iter(&self) -> impl Iterator<Item = &T> {
|
||||
self.queue.iter()
|
||||
}
|
||||
|
||||
crate fn take(&mut self) -> Option<T> {
|
||||
self.queue.pop_front()
|
||||
}
|
||||
|
||||
crate fn add(&mut self, value: T) {
|
||||
self.queue.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(new)]
|
||||
pub struct Streams {
|
||||
#[new(value = "ObjectStream::empty()")]
|
||||
success: ObjectStream<Value>,
|
||||
|
||||
#[new(value = "ObjectStream::empty()")]
|
||||
errors: ObjectStream<ShellError>,
|
||||
|
||||
#[new(value = "ObjectStream::empty()")]
|
||||
log: ObjectStream<LogItem>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Streams {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "Streams")
|
||||
}
|
||||
}
|
||||
|
||||
impl Streams {
|
||||
crate fn read(&mut self) -> Option<Value> {
|
||||
self.success.take()
|
||||
}
|
||||
|
||||
crate fn add(&mut self, value: Value) {
|
||||
self.success.add(value);
|
||||
}
|
||||
|
||||
// fn take_stream(&mut self, stream: &mut ObjectStream) -> ObjectStream {
|
||||
// let mut new_stream = Cell::new(ObjectStream::default());
|
||||
// new_stream.swap()
|
||||
// std::mem::swap(stream, &mut new_stream);
|
||||
// new_stream
|
||||
// }
|
||||
}
|
||||
|
||||
#[derive(Debug, new)]
|
||||
pub struct Args {
|
||||
argv: Vec<Value>,
|
||||
#[new(value = "Streams::new()")]
|
||||
streams: Streams,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
crate fn first(&self) -> Option<&Value> {
|
||||
self.argv.first()
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{dir_entry_dict, Value};
|
||||
use crate::object::Value;
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
use std::path::{Path, PathBuf};
|
||||
use sysinfo::SystemExt;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(new)]
|
||||
pub struct CdBlueprint;
|
||||
@ -14,7 +11,7 @@ impl crate::CommandBlueprint for CdBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<Value>,
|
||||
host: &dyn Host,
|
||||
_host: &dyn Host,
|
||||
env: &mut Environment,
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
let target = match args.first() {
|
||||
@ -37,7 +34,7 @@ pub struct Cd {
|
||||
}
|
||||
|
||||
impl crate::Command for Cd {
|
||||
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
fn run(&mut self, _stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let mut stream = VecDeque::new();
|
||||
let path = dunce::canonicalize(self.cwd.join(&self.target).as_path())?;
|
||||
stream.push_back(ReturnValue::change_cwd(path));
|
||||
|
@ -1,12 +1,9 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{dir_entry_dict, Value};
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use crate::Command;
|
||||
use derive_new::new;
|
||||
use std::path::PathBuf;
|
||||
use sysinfo::SystemExt;
|
||||
|
||||
#[derive(new)]
|
||||
pub struct LsBlueprint;
|
||||
@ -14,8 +11,8 @@ pub struct LsBlueprint;
|
||||
impl crate::CommandBlueprint for LsBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<Value>,
|
||||
host: &dyn crate::Host,
|
||||
_args: Vec<Value>,
|
||||
_host: &dyn crate::Host,
|
||||
env: &mut crate::Environment,
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
Ok(Box::new(Ls {
|
||||
@ -30,9 +27,9 @@ pub struct Ls {
|
||||
}
|
||||
|
||||
impl crate::Command for Ls {
|
||||
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
fn run(&mut self, _stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let entries =
|
||||
std::fs::read_dir(&self.cwd).map_err((|e| ShellError::string(format!("{:?}", e))))?;
|
||||
std::fs::read_dir(&self.cwd).map_err(|e| ShellError::string(format!("{:?}", e)))?;
|
||||
|
||||
let mut shell_entries = VecDeque::new();
|
||||
|
||||
|
@ -4,8 +4,6 @@ use crate::object::Value;
|
||||
use crate::prelude::*;
|
||||
use crate::Command;
|
||||
use derive_new::new;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use sysinfo::SystemExt;
|
||||
|
||||
#[derive(new)]
|
||||
@ -14,9 +12,9 @@ pub struct PsBlueprint;
|
||||
impl crate::CommandBlueprint for PsBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<Value>,
|
||||
host: &dyn crate::Host,
|
||||
env: &mut crate::Environment,
|
||||
_args: Vec<Value>,
|
||||
_host: &dyn crate::Host,
|
||||
_env: &mut crate::Environment,
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
Ok(Box::new(Ps::new()))
|
||||
}
|
||||
@ -26,7 +24,7 @@ impl crate::CommandBlueprint for PsBlueprint {
|
||||
pub struct Ps;
|
||||
|
||||
impl crate::Command for Ps {
|
||||
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
fn run(&mut self, _stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let mut system = sysinfo::System::new();
|
||||
system.refresh_all();
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::base::reject;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{dir_entry_dict, Value};
|
||||
use crate::object::Value;
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
use std::path::{Path, PathBuf};
|
||||
use sysinfo::SystemExt;
|
||||
|
||||
#[derive(new)]
|
||||
pub struct RejectBlueprint;
|
||||
@ -15,8 +11,8 @@ impl crate::CommandBlueprint for RejectBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<Value>,
|
||||
host: &dyn Host,
|
||||
env: &mut Environment,
|
||||
_host: &dyn Host,
|
||||
_env: &mut Environment,
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
if args.is_empty() {
|
||||
return Err(ShellError::string("take requires an integer"));
|
||||
|
@ -1,12 +1,8 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::base::select;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{dir_entry_dict, Value};
|
||||
use crate::object::Value;
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
use std::path::{Path, PathBuf};
|
||||
use sysinfo::SystemExt;
|
||||
|
||||
#[derive(new)]
|
||||
pub struct SelectBlueprint;
|
||||
@ -15,8 +11,8 @@ impl crate::CommandBlueprint for SelectBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<Value>,
|
||||
host: &dyn Host,
|
||||
env: &mut Environment,
|
||||
_host: &dyn Host,
|
||||
_env: &mut Environment,
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
if args.is_empty() {
|
||||
return Err(ShellError::string("take requires an integer"));
|
||||
|
@ -1,11 +1,7 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{dir_entry_dict, Value};
|
||||
use crate::object::Value;
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
use std::path::{Path, PathBuf};
|
||||
use sysinfo::SystemExt;
|
||||
|
||||
#[derive(new)]
|
||||
pub struct TakeBlueprint;
|
||||
@ -14,8 +10,8 @@ impl crate::CommandBlueprint for TakeBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<Value>,
|
||||
host: &dyn Host,
|
||||
env: &mut Environment,
|
||||
_host: &dyn Host,
|
||||
_env: &mut Environment,
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
if args.is_empty() {
|
||||
return Err(ShellError::string("take requires an integer"));
|
||||
|
@ -1,11 +1,7 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{dir_entry_dict, Value};
|
||||
use crate::object::Value;
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
use std::path::{Path, PathBuf};
|
||||
use sysinfo::SystemExt;
|
||||
|
||||
#[derive(new)]
|
||||
pub struct ToArrayBlueprint;
|
||||
@ -13,9 +9,9 @@ pub struct ToArrayBlueprint;
|
||||
impl crate::CommandBlueprint for ToArrayBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<Value>,
|
||||
host: &dyn Host,
|
||||
env: &mut Environment,
|
||||
_args: Vec<Value>,
|
||||
_host: &dyn Host,
|
||||
_env: &mut Environment,
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
Ok(Box::new(ToArray))
|
||||
}
|
||||
|
Reference in New Issue
Block a user