-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinspect_request.rs
43 lines (35 loc) · 1.34 KB
/
inspect_request.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::io::stdout;
use async_trait::async_trait;
use super::ViewCommand;
use crate::app::backend::Backend;
use crate::view::output::utils::BREAK_LINE;
use crate::view::output::writer::{CliWriterRepository, CrosstermCliWriter};
use crate::view::style::{Color, StyledStr};
pub struct InspectRequestExecutor<Writer: CliWriterRepository> {
pub request_name: String,
pub writer: Writer,
}
impl InspectRequestExecutor<CrosstermCliWriter> {
pub fn new(request_name: String) -> Self {
InspectRequestExecutor {
request_name,
writer: CrosstermCliWriter::from(Box::new(stdout())),
}
}
}
#[async_trait]
impl<Writer: CliWriterRepository> ViewCommand for InspectRequestExecutor<Writer> {
async fn execute(mut self: Box<Self>, provider: &mut dyn Backend) -> anyhow::Result<()> {
self.writer.print_lines([BREAK_LINE]);
self.writer.print_lines_styled([[
StyledStr::from(" Request data of "),
StyledStr::from(&self.request_name).with_color_text(Color::Yellow),
]]);
self.writer.print_lines([BREAK_LINE]);
let request_data = provider.get_request_saved(self.request_name).await?;
let output = serde_json::to_string_pretty(&request_data)?;
self.writer.print_lines([output]);
self.writer.print_lines([BREAK_LINE]);
Ok(())
}
}