Compare commits
5 commits
f12de31125
...
748e81af4b
Author | SHA1 | Date | |
---|---|---|---|
748e81af4b | |||
bf8a5fde9a | |||
77324017c2 | |||
324b7ce705 | |||
cb225ae7de |
5 changed files with 39 additions and 14 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -260,6 +260,12 @@ version = "0.8.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "dotenv"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
|
||||
|
||||
[[package]]
|
||||
name = "dyn-clone"
|
||||
version = "1.0.17"
|
||||
|
@ -815,11 +821,12 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
|||
|
||||
[[package]]
|
||||
name = "postwoman"
|
||||
version = "0.4.3"
|
||||
version = "0.4.4"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"chrono",
|
||||
"clap",
|
||||
"dotenv",
|
||||
"http",
|
||||
"indexmap",
|
||||
"jaq-interpret",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "postwoman"
|
||||
description = "API tester and debugger for your CLI "
|
||||
version = "0.4.3"
|
||||
version = "0.4.4"
|
||||
repository = "https://moonlit.technology/alemi/postwoman"
|
||||
authors = [ "alemi <me@alemi.dev>" ]
|
||||
license = "GPL-3.0-only"
|
||||
|
@ -13,6 +13,7 @@ edition = "2021"
|
|||
base64 = "0.22.1"
|
||||
chrono = "0.4"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
dotenv = "0.15"
|
||||
http = "1.1.0"
|
||||
indexmap = { version = "2.6", features = ["serde"] }
|
||||
jaq-interpret = "1.5"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
include = ["other.toml", "api/auth.toml"] # include other postwoman collections relative to this one
|
||||
#include = ["other.toml", "api/auth.toml"] # include other postwoman collections relative to this one
|
||||
|
||||
[env] # these will be replaced in fields and inherited by includes. environment vars overrule these
|
||||
PW_TOKEN = "set-me-as-and-environment-variable!"
|
||||
|
|
28
src/fmt.rs
28
src/fmt.rs
|
@ -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:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -23,6 +23,10 @@ struct PostWomanArgs {
|
|||
#[arg(short, long, default_value = "postwoman.toml")]
|
||||
collection: std::path::PathBuf,
|
||||
|
||||
/// environment (.env) to load
|
||||
#[arg(short, long, default_value = ".env")]
|
||||
env: std::path::PathBuf,
|
||||
|
||||
/// action to run
|
||||
#[clap(subcommand)]
|
||||
action: Option<PostWomanActions>,
|
||||
|
@ -86,6 +90,12 @@ fn main() {
|
|||
},
|
||||
|
||||
PostWomanActions::Run { query, parallel, debug, dry_run } => {
|
||||
eprintln!("~@ {APP_USER_AGENT}");
|
||||
|
||||
if dotenv::from_path(&args.env).is_ok() {
|
||||
eprintln!(" # loaded env file {:?}", args.env);
|
||||
}
|
||||
|
||||
// note that if you remove this test, there's another .expect() below you need to manage too!
|
||||
let filter = match regex::Regex::new(query) {
|
||||
Ok(regex) => regex,
|
||||
|
@ -114,7 +124,6 @@ fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
eprintln!("~@ {APP_USER_AGENT}");
|
||||
if multi_thread {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
|
|
Loading…
Reference in a new issue