mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 01:09:51 +02:00
Continue prepping for object streams
This commit is contained in:
@@ -1,6 +1,31 @@
|
||||
use crate::Value;
|
||||
use crate::object::Value;
|
||||
use derive_new::new;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Args {
|
||||
args: Vec<Value>,
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ObjectStream {
|
||||
queue: VecDeque<Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Streams {
|
||||
success: ObjectStream,
|
||||
error: ObjectStream,
|
||||
warning: ObjectStream,
|
||||
debug: ObjectStream,
|
||||
trace: ObjectStream,
|
||||
verbose: ObjectStream,
|
||||
}
|
||||
|
||||
#[derive(Debug, new)]
|
||||
pub struct Args {
|
||||
argv: Vec<Value>,
|
||||
#[new(default)]
|
||||
streams: Streams,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
crate fn first(&self) -> Option<&Value> {
|
||||
self.argv.first()
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{DirEntry, ShellObject, Value};
|
||||
use crate::Args;
|
||||
use derive_new::new;
|
||||
use std::path::{Path, PathBuf};
|
||||
use sysinfo::SystemExt;
|
||||
@@ -11,14 +12,20 @@ pub struct CdBlueprint;
|
||||
impl crate::CommandBlueprint for CdBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<String>,
|
||||
args: Args,
|
||||
host: &dyn crate::Host,
|
||||
env: &mut crate::Environment,
|
||||
) -> Box<dyn crate::Command> {
|
||||
Box::new(Cd {
|
||||
) -> Result<Box<dyn crate::Command>, ShellError> {
|
||||
let target = match args.first() {
|
||||
// TODO: This needs better infra
|
||||
None => return Err(ShellError::new(format!("cd must take one arg"))),
|
||||
Some(v) => v.as_string()?.clone(),
|
||||
};
|
||||
|
||||
Ok(Box::new(Cd {
|
||||
cwd: env.cwd().to_path_buf(),
|
||||
target: args[0].clone(),
|
||||
})
|
||||
target,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,10 +5,10 @@ use std::path::PathBuf;
|
||||
pub trait CommandBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<String>,
|
||||
args: crate::Args,
|
||||
host: &dyn crate::Host,
|
||||
env: &mut crate::Environment,
|
||||
) -> Box<dyn Command>;
|
||||
) -> Result<Box<dyn Command>, ShellError>;
|
||||
}
|
||||
|
||||
crate enum CommandAction {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::process::Process;
|
||||
use crate::object::{DirEntry, ShellObject, Value};
|
||||
use crate::Args;
|
||||
use crate::{Command, CommandSuccess};
|
||||
use derive_new::new;
|
||||
use std::path::PathBuf;
|
||||
@@ -12,13 +13,13 @@ pub struct LsBlueprint;
|
||||
impl crate::CommandBlueprint for LsBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<String>,
|
||||
args: Args,
|
||||
host: &dyn crate::Host,
|
||||
env: &mut crate::Environment,
|
||||
) -> Box<dyn Command> {
|
||||
Box::new(Ls {
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
Ok(Box::new(Ls {
|
||||
cwd: env.cwd().to_path_buf(),
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -15,11 +15,11 @@ pub struct PsBlueprint {
|
||||
impl crate::CommandBlueprint for PsBlueprint {
|
||||
fn create(
|
||||
&self,
|
||||
args: Vec<String>,
|
||||
args: crate::Args,
|
||||
host: &dyn crate::Host,
|
||||
env: &mut crate::Environment,
|
||||
) -> Box<dyn Command> {
|
||||
Box::new(Ps::new(self.system.clone()))
|
||||
) -> Result<Box<dyn Command>, ShellError> {
|
||||
Ok(Box::new(Ps::new(self.system.clone())))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user