mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 05:10:18 +02:00
Strip away a bit of cruft and add reject
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{DirEntry, ShellObject, Value};
|
||||
use crate::object::{dir_entry_dict, ShellObject, Value};
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{DirEntry, ShellObject, Value};
|
||||
use crate::object::{dir_entry_dict, ShellObject, Value};
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use crate::Command;
|
||||
@@ -37,7 +37,7 @@ impl crate::Command for Ls {
|
||||
let mut shell_entries = VecDeque::new();
|
||||
|
||||
for entry in entries {
|
||||
let value = Value::object(DirEntry::new(entry?)?);
|
||||
let value = Value::Object(dir_entry_dict(&entry?)?);
|
||||
shell_entries.push_back(ReturnValue::Value(value))
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::process::process_dict;
|
||||
use crate::object::{ShellObject, Value};
|
||||
use crate::prelude::*;
|
||||
use crate::Command;
|
||||
@@ -34,9 +34,7 @@ impl crate::Command for Ps {
|
||||
|
||||
let list = list
|
||||
.into_iter()
|
||||
.map(|(_, process)| {
|
||||
ReturnValue::Value(Value::Object(Box::new(Process::new(process.clone()))))
|
||||
})
|
||||
.map(|(_, process)| ReturnValue::Value(Value::Object(process_dict(process))))
|
||||
.collect::<VecDeque<_>>();
|
||||
|
||||
Ok(list)
|
||||
|
46
src/commands/reject.rs
Normal file
46
src/commands/reject.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::base::reject;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{dir_entry_dict, ShellObject, Value};
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
use std::path::{Path, PathBuf};
|
||||
use sysinfo::SystemExt;
|
||||
|
||||
#[derive(new)]
|
||||
pub struct RejectBlueprint;
|
||||
|
||||
impl crate::CommandBlueprint for RejectBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<Value>,
|
||||
host: &dyn Host,
|
||||
env: &mut Environment,
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
if args.is_empty() {
|
||||
return Err(ShellError::string("take requires an integer"));
|
||||
}
|
||||
|
||||
let fields: Result<_, _> = args.iter().map(|a| a.as_string()).collect();
|
||||
|
||||
Ok(Box::new(Reject { fields: fields? }))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(new)]
|
||||
pub struct Reject {
|
||||
fields: Vec<String>,
|
||||
}
|
||||
|
||||
impl crate::Command for Reject {
|
||||
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let objects = stream
|
||||
.iter()
|
||||
.map(|item| Value::Object(reject(item, &self.fields)))
|
||||
.map(|item| ReturnValue::Value(item))
|
||||
.collect();
|
||||
|
||||
Ok(objects)
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::base::select;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{DirEntry, ShellObject, Value};
|
||||
use crate::object::{dir_entry_dict, ShellObject, Value};
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
@@ -37,7 +37,7 @@ impl crate::Command for Select {
|
||||
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let objects = stream
|
||||
.iter()
|
||||
.map(|item| Value::Object(Box::new(select(item, &self.fields))))
|
||||
.map(|item| Value::Object(select(item, &self.fields)))
|
||||
.map(|item| ReturnValue::Value(item))
|
||||
.collect();
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{DirEntry, ShellObject, Value};
|
||||
use crate::object::{dir_entry_dict, ShellObject, Value};
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{DirEntry, ShellObject, Value};
|
||||
use crate::object::{dir_entry_dict, ShellObject, Value};
|
||||
use crate::prelude::*;
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
|
Reference in New Issue
Block a user