feat: better formatting on stdout

This commit is contained in:
əlemi 2024-10-30 02:37:59 +01:00
parent 324b7ce705
commit 77324017c2
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,6 +1,6 @@
use indexmap::IndexMap;
use crate::{PostWomanCollection, PostWomanError};
use crate::{ext::StringOr, model::ExtractorConfig, PostWomanCollection, PostWomanError};
pub const TIMESTAMP_FMT: &str = "%H:%M:%S%.6f";
@ -57,10 +57,10 @@ impl PrintableResult for ListResult {
fn print(self) {
let (collections, compact) = self;
for (namespace, collection) in collections {
println!("-> {namespace}");
println!("+#> {namespace}");
for (key, value) in collection.env {
println!(" + {key}={}", crate::ext::stringify_toml(&value));
println!("| {key}={}", crate::ext::stringify_toml(&value));
}
for (name, endpoint) in collection.route {
@ -70,23 +70,31 @@ impl PrintableResult for ListResult {
.unwrap_or_default()
.to_string();
let method = endpoint.method.as_deref().unwrap_or("GET");
println!(" - {name} \t{method} \t{url}");
if !compact { println!("|") };
println!("|- {name: <30} {method: <10} {url}");
if ! compact {
if let Some(ref query) = endpoint.query {
for query in query {
println!(" |? {query}");
for (i, query) in query.iter().enumerate() {
println!("| {}| {query}", if i == 0 { "Q" } else { " " });
}
}
if let Some(ref headers) = endpoint.headers {
for header in headers {
println!(" |: {header}");
for (i, header) in headers.iter().enumerate() {
println!("| {}| {header}", if i == 0 { "H" } else { " " });
}
}
if let Some(ref _x) = endpoint.body {
if let Ok(body) = endpoint.body() {
println!(" |> {}", body.replace("\n", "\n |> "));
println!("| B| {}", body.replace("\n", "\n| | "));
} else {
println!(" |> [!] invalid body");
println!("| B| [!] invalid body");
}
}
if let Some(ref extract) = endpoint.extract {
match extract {
StringOr::Str(q) => println!("| E| {:?}", ExtractorConfig::JQ { query: q.to_string() }),
StringOr::T(ext) => println!("| E| {ext:?}"),
}
}
}