aboutsummaryrefslogtreecommitdiff
path: root/src/executor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/executor.rs')
-rw-r--r--src/executor.rs31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/executor.rs b/src/executor.rs
index bd948b5..40a2857 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -1,9 +1,11 @@
use crate::barbfile::BarbFile;
+use crate::output::BarbOutput;
use std::collections::HashMap;
use ureq;
use ureq::Error as UreqError;
+
pub struct Context {
vars: HashMap<String, String>,
}
@@ -57,32 +59,24 @@ impl Executor {
Executor { context }
}
- fn make_req(&self, bfile: &BarbFile, print_req: bool, print_headers: bool) -> ureq::Request {
- if print_req {
- println!(
- "{} {}",
- bfile.method_as_string().as_str(),
- self.context.substitute(&bfile.url()).as_str()
- );
- }
+ fn make_req(&self, bfile: &BarbFile, output: &BarbOutput) -> ureq::Request {
+ output.req(bfile.method_as_string(), self.context.substitute(&bfile.url()));
let mut req = ureq::request(
bfile.method_as_string().as_str(),
self.context.substitute(&bfile.url()).as_str(),
);
for header in bfile.headers() {
+ let hdr_val = self.context.substitute(header.value());
req = req.set(
header.name(),
- self.context.substitute(header.value()).as_str(),
+ hdr_val.as_str(),
);
- if print_headers {
- println!(
- "{} {}",
- header.name(),
- self.context.substitute(header.value())
- );
- }
+ output.req_hdr(header.name().to_string(), hdr_val);
}
+
+ output.end_req();
+
req
}
@@ -105,10 +99,9 @@ impl Executor {
pub fn execute(
&mut self,
bfile: &BarbFile,
- print_req: bool,
- print_headers: bool,
+ output: &BarbOutput,
) -> Result<ureq::Response, String> {
- self.run(bfile, self.make_req(&bfile, print_req, print_headers))
+ self.run(bfile, self.make_req(&bfile, output))
}
}