feat: better formatting on stdout
This commit is contained in:
parent
324b7ce705
commit
77324017c2
1 changed files with 18 additions and 10 deletions
28
src/fmt.rs
28
src/fmt.rs
|
@ -1,6 +1,6 @@
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
|
||||||
use crate::{PostWomanCollection, PostWomanError};
|
use crate::{ext::StringOr, model::ExtractorConfig, PostWomanCollection, PostWomanError};
|
||||||
|
|
||||||
pub const TIMESTAMP_FMT: &str = "%H:%M:%S%.6f";
|
pub const TIMESTAMP_FMT: &str = "%H:%M:%S%.6f";
|
||||||
|
|
||||||
|
@ -57,10 +57,10 @@ impl PrintableResult for ListResult {
|
||||||
fn print(self) {
|
fn print(self) {
|
||||||
let (collections, compact) = self;
|
let (collections, compact) = self;
|
||||||
for (namespace, collection) in collections {
|
for (namespace, collection) in collections {
|
||||||
println!("-> {namespace}");
|
println!("+#> {namespace}");
|
||||||
|
|
||||||
for (key, value) in collection.env {
|
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 {
|
for (name, endpoint) in collection.route {
|
||||||
|
@ -70,23 +70,31 @@ impl PrintableResult for ListResult {
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string();
|
.to_string();
|
||||||
let method = endpoint.method.as_deref().unwrap_or("GET");
|
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 ! compact {
|
||||||
if let Some(ref query) = endpoint.query {
|
if let Some(ref query) = endpoint.query {
|
||||||
for query in query {
|
for (i, query) in query.iter().enumerate() {
|
||||||
println!(" |? {query}");
|
println!("| {}| {query}", if i == 0 { "Q" } else { " " });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(ref headers) = endpoint.headers {
|
if let Some(ref headers) = endpoint.headers {
|
||||||
for header in headers {
|
for (i, header) in headers.iter().enumerate() {
|
||||||
println!(" |: {header}");
|
println!("| {}| {header}", if i == 0 { "H" } else { " " });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(ref _x) = endpoint.body {
|
if let Some(ref _x) = endpoint.body {
|
||||||
if let Ok(body) = endpoint.body() {
|
if let Ok(body) = endpoint.body() {
|
||||||
println!(" |> {}", body.replace("\n", "\n |> "));
|
println!("| B| {}", body.replace("\n", "\n| | "));
|
||||||
} else {
|
} 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:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue