diff --git a/src/commands/args.rs b/src/commands/args.rs index 183876b58..1cedae9c5 100644 --- a/src/commands/args.rs +++ b/src/commands/args.rs @@ -1,5 +1,6 @@ use crate::object::Value; use derive_new::new; +use std::cell::Cell; use std::collections::VecDeque; #[derive(Debug, Default)] @@ -7,20 +8,46 @@ pub struct ObjectStream { queue: VecDeque, } -#[derive(Debug, Default)] pub struct Streams { - success: ObjectStream, - error: ObjectStream, - warning: ObjectStream, - debug: ObjectStream, - trace: ObjectStream, - verbose: ObjectStream, + success: Cell, + // error: ObjectStream, + // warning: ObjectStream, + // debug: ObjectStream, + // trace: ObjectStream, + // verbose: ObjectStream, +} + +impl std::fmt::Debug for Streams { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "Streams") + } +} + +impl Streams { + crate fn new() -> Streams { + Streams { + success: Cell::new(ObjectStream::default()), + } + } + + crate fn take_success(&mut self) -> Cell { + let new_stream = Cell::new(ObjectStream::default()); + self.success.swap(&new_stream); + new_stream + } + + // 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, - #[new(default)] + #[new(value = "Streams::new()")] streams: Streams, } diff --git a/src/commands/command.rs b/src/commands/command.rs index a62a593ee..d3385465c 100644 --- a/src/commands/command.rs +++ b/src/commands/command.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; pub trait CommandBlueprint { fn create( &self, - args: crate::Args, + input: crate::Args, host: &dyn crate::Host, env: &mut crate::Environment, ) -> Result, ShellError>;