Compare commits

..

No commits in common. "748e81af4b9c6e01a025e9c0c6a39f2fd24a6e6e" and "f12de311254873794e5e09ce5ad4da43f2c24737" have entirely different histories.

5 changed files with 14 additions and 39 deletions

9
Cargo.lock generated
View file

@ -260,12 +260,6 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "dyn-clone" name = "dyn-clone"
version = "1.0.17" version = "1.0.17"
@ -821,12 +815,11 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]] [[package]]
name = "postwoman" name = "postwoman"
version = "0.4.4" version = "0.4.3"
dependencies = [ dependencies = [
"base64", "base64",
"chrono", "chrono",
"clap", "clap",
"dotenv",
"http", "http",
"indexmap", "indexmap",
"jaq-interpret", "jaq-interpret",

View file

@ -1,7 +1,7 @@
[package] [package]
name = "postwoman" name = "postwoman"
description = "API tester and debugger for your CLI " description = "API tester and debugger for your CLI "
version = "0.4.4" version = "0.4.3"
repository = "https://moonlit.technology/alemi/postwoman" repository = "https://moonlit.technology/alemi/postwoman"
authors = [ "alemi <me@alemi.dev>" ] authors = [ "alemi <me@alemi.dev>" ]
license = "GPL-3.0-only" license = "GPL-3.0-only"
@ -13,7 +13,6 @@ edition = "2021"
base64 = "0.22.1" base64 = "0.22.1"
chrono = "0.4" chrono = "0.4"
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
dotenv = "0.15"
http = "1.1.0" http = "1.1.0"
indexmap = { version = "2.6", features = ["serde"] } indexmap = { version = "2.6", features = ["serde"] }
jaq-interpret = "1.5" jaq-interpret = "1.5"

View file

@ -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 [env] # these will be replaced in fields and inherited by includes. environment vars overrule these
PW_TOKEN = "set-me-as-and-environment-variable!" PW_TOKEN = "set-me-as-and-environment-variable!"

View file

@ -1,6 +1,6 @@
use indexmap::IndexMap; use indexmap::IndexMap;
use crate::{ext::StringOr, model::ExtractorConfig, PostWomanCollection, PostWomanError}; use crate::{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,31 +70,23 @@ 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");
if !compact { println!("|") }; println!(" - {name} \t{method} \t{url}");
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 (i, query) in query.iter().enumerate() { for query in query {
println!("| {}| {query}", if i == 0 { "Q" } else { " " }); println!(" |? {query}");
} }
} }
if let Some(ref headers) = endpoint.headers { if let Some(ref headers) = endpoint.headers {
for (i, header) in headers.iter().enumerate() { for header in headers {
println!("| {}| {header}", if i == 0 { "H" } else { " " }); println!(" |: {header}");
} }
} }
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!("| B| {}", body.replace("\n", "\n| | ")); println!(" |> {}", body.replace("\n", "\n |> "));
} else { } else {
println!("| B| [!] invalid body"); println!(" |> [!] 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:?}"),
} }
} }
} }

View file

@ -23,10 +23,6 @@ struct PostWomanArgs {
#[arg(short, long, default_value = "postwoman.toml")] #[arg(short, long, default_value = "postwoman.toml")]
collection: std::path::PathBuf, collection: std::path::PathBuf,
/// environment (.env) to load
#[arg(short, long, default_value = ".env")]
env: std::path::PathBuf,
/// action to run /// action to run
#[clap(subcommand)] #[clap(subcommand)]
action: Option<PostWomanActions>, action: Option<PostWomanActions>,
@ -90,12 +86,6 @@ fn main() {
}, },
PostWomanActions::Run { query, parallel, debug, dry_run } => { 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! // note that if you remove this test, there's another .expect() below you need to manage too!
let filter = match regex::Regex::new(query) { let filter = match regex::Regex::new(query) {
Ok(regex) => regex, Ok(regex) => regex,
@ -124,6 +114,7 @@ fn main() {
} }
}; };
eprintln!("~@ {APP_USER_AGENT}");
if multi_thread { if multi_thread {
tokio::runtime::Builder::new_multi_thread() tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()