Linting and other cleanup

This commit is contained in:
Yehuda Katz
2019-05-24 12:35:22 -07:00
parent 9f8d2a4de5
commit bd055f2af1
11 changed files with 46 additions and 96 deletions

View File

@@ -1,5 +1,4 @@
use crate::prelude::*;
use futures::compat::AsyncRead01CompatExt;
use futures_codec::{Framed, LinesCodec};
use std::sync::Arc;
use subprocess::Exec;
@@ -37,44 +36,6 @@ crate enum ClassifiedCommand {
External(ExternalCommand),
}
impl ClassifiedCommand {
crate async fn run(
self,
context: &mut Context,
input: ClassifiedInputStream,
) -> Result<InputStream, ShellError> {
match self {
ClassifiedCommand::Internal(internal) => {
let result = context.run_command(internal.command, internal.args, input.objects)?;
let env = context.env.clone();
let stream = result.filter_map(move |v| match v {
ReturnValue::Action(action) => match action {
CommandAction::ChangeCwd(cwd) => {
env.lock().unwrap().cwd = cwd;
futures::future::ready(None)
}
},
ReturnValue::Value(v) => futures::future::ready(Some(v)),
});
Ok(stream.boxed() as InputStream)
}
ClassifiedCommand::External(external) => {
Exec::shell(&external.name)
.args(&external.args)
.cwd(context.env.lock().unwrap().cwd())
.join()
.unwrap();
Ok(VecDeque::new().boxed() as InputStream)
}
}
}
}
crate struct InternalCommand {
crate command: Arc<dyn Command>,
crate args: Vec<Value>,
@@ -119,10 +80,10 @@ impl ExternalCommand {
crate async fn run(
self,
context: &mut Context,
mut input: ClassifiedInputStream,
input: ClassifiedInputStream,
stream_next: StreamNext,
) -> Result<ClassifiedInputStream, ShellError> {
let mut process = Exec::shell(&self.name)
let process = Exec::shell(&self.name)
.args(&self.args)
.cwd(context.env.lock().unwrap().cwd());
@@ -156,14 +117,5 @@ impl ExternalCommand {
Ok(ClassifiedInputStream::from_input_stream(stream.boxed()))
}
}
// if stream_next {
// let stdout = popen.stdout.take().unwrap();
// Ok(ClassifiedInputStream::from_stdout(stdout))
// } else {
// // popen.stdin.take();
// popen.wait()?;
// Ok(ClassifiedInputStream::new())
// }
}
}

16
src/commands/format.rs Normal file
View File

@@ -0,0 +1,16 @@
use crate::prelude::*;
use crate::{EntriesListView, GenericView};
use futures::stream::{self, StreamExt};
use std::sync::{Arc, Mutex};
crate fn format(input: Vec<Value>, host: &mut dyn Host) {
let last = input.len() - 1;
for (i, item) in input.iter().enumerate() {
let view = GenericView::new(item);
crate::format::print_view(&view, &mut *host);
if last != i {
println!("");
}
}
}