fix: Better enforce typing for commands
This commit is contained in:
@@ -6,7 +6,7 @@ use syn::{
|
||||
Error, Token,
|
||||
};
|
||||
|
||||
use crate::{cmd::Value, macros::enum_to_tokens};
|
||||
use crate::cmd::Value;
|
||||
|
||||
pub struct Pipe {
|
||||
stdin: Option<Value>,
|
||||
@@ -47,7 +47,7 @@ impl ToTokens for Pipe {
|
||||
let first_command = commands_iter.next().unwrap();
|
||||
|
||||
let initial = quote! {
|
||||
let mut _c_0 = #first_command;
|
||||
let mut _c_0: #first_command;
|
||||
_c_0.stdout(::std::process::Stdio::piped());
|
||||
_c_0.stdin(::std::process::Stdio::piped());
|
||||
let mut _child_0 = _c_0.spawn()?;
|
||||
@@ -95,7 +95,7 @@ impl ToTokens for Pipe {
|
||||
});
|
||||
}
|
||||
|
||||
let mut #com_ident = #command;
|
||||
let mut #com_ident: #command;
|
||||
#com_ident.stdout(::std::process::Stdio::piped());
|
||||
#com_ident.stdin(::std::process::Stdio::piped());
|
||||
|
||||
@@ -171,4 +171,21 @@ impl Parse for CommandExpr {
|
||||
}
|
||||
}
|
||||
|
||||
enum_to_tokens! {CommandExpr: Macro, Reference, Function, Block}
|
||||
impl ToTokens for CommandExpr {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
tokens.extend(match self {
|
||||
Self::Macro(macr) => quote! {
|
||||
::std::process::Command = #macr
|
||||
},
|
||||
Self::Reference(refer) => quote! {
|
||||
&mut ::std::process::Command = #refer
|
||||
},
|
||||
Self::Function(fun) => quote! {
|
||||
::std::process::Command = #fun
|
||||
},
|
||||
Self::Block(block) => quote! {
|
||||
::std::process::Command = #block
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user