Compare commits
No commits in common. "b9271ad47d564b35e9eef6e34740c55e46d3d906" and "0af5adec5abd41d75295e317912fbf2130feaa89" have entirely different histories.
b9271ad47d
...
0af5adec5a
2 changed files with 14 additions and 29 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -815,7 +815,7 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
|||
|
||||
[[package]]
|
||||
name = "postwoman"
|
||||
version = "0.3.2"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"chrono",
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -2,11 +2,10 @@ mod model;
|
|||
mod errors;
|
||||
mod ext;
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
use indexmap::IndexMap;
|
||||
pub use model::PostWomanCollection;
|
||||
pub use errors::PostWomanError;
|
||||
|
||||
|
@ -25,7 +24,7 @@ struct PostWomanArgs {
|
|||
action: Option<PostWomanActions>,
|
||||
|
||||
/// start a multi-thread runtime, with multiple worker threads
|
||||
#[arg(short = 'M', long, default_value_t = false)]
|
||||
#[arg(long, default_value_t = false)]
|
||||
multi_threaded: bool,
|
||||
}
|
||||
|
||||
|
@ -43,10 +42,6 @@ pub enum PostWomanActions {
|
|||
/// force debug extractor on all routes
|
||||
#[arg(long, default_value_t = false)]
|
||||
debug: bool,
|
||||
|
||||
/// print matched routes but don't perform requests
|
||||
#[arg(long, default_value_t = false)]
|
||||
dry_run: bool,
|
||||
},
|
||||
|
||||
/// show all registered routes in current collection
|
||||
|
@ -71,7 +66,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
let mut collections = IndexMap::new();
|
||||
let mut collections = HashMap::new();
|
||||
|
||||
if !load_collections(&mut collections, args.collection.clone()) {
|
||||
return;
|
||||
|
@ -109,7 +104,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
fn load_collections(store: &mut IndexMap<String, PostWomanCollection>, mut path: std::path::PathBuf) -> bool {
|
||||
fn load_collections(store: &mut HashMap<String, PostWomanCollection>, mut path: std::path::PathBuf) -> bool {
|
||||
let collection_raw = match std::fs::read_to_string(&path) {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
|
@ -127,7 +122,6 @@ fn load_collections(store: &mut IndexMap<String, PostWomanCollection>, mut path:
|
|||
};
|
||||
|
||||
let name = path.to_string_lossy().to_string();
|
||||
let mut to_include = Vec::new();
|
||||
|
||||
if let Some(ref includes) = collection.include {
|
||||
path.pop();
|
||||
|
@ -135,17 +129,13 @@ fn load_collections(store: &mut IndexMap<String, PostWomanCollection>, mut path:
|
|||
let mut base = path.clone();
|
||||
let new = std::path::PathBuf::from_str(include).expect("infallible");
|
||||
base.push(new);
|
||||
to_include.push(base);
|
||||
}
|
||||
}
|
||||
|
||||
store.insert(name, collection);
|
||||
|
||||
for base in to_include {
|
||||
if !load_collections(store, base) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
store.insert(name, collection);
|
||||
|
||||
true
|
||||
}
|
||||
|
@ -189,7 +179,7 @@ async fn run_postwoman(args: &PostWomanArgs, namespace: String, collection: Post
|
|||
|
||||
println!();
|
||||
},
|
||||
PostWomanActions::Run { query, parallel, debug, dry_run } => {
|
||||
PostWomanActions::Run { query, parallel, debug } => {
|
||||
// this is always safe to compile because we tested it beforehand
|
||||
let pattern = regex::Regex::new(query).expect("tested it before and still failed here???");
|
||||
let client = std::sync::Arc::new(collection.client.unwrap_or_default());
|
||||
|
@ -200,21 +190,16 @@ async fn run_postwoman(args: &PostWomanArgs, namespace: String, collection: Post
|
|||
let _client = client.clone();
|
||||
let _env = env.clone();
|
||||
let _endpoint = endpoint.clone();
|
||||
let _dry_run = *dry_run;
|
||||
let _name = name.clone();
|
||||
let _namespace = namespace.clone();
|
||||
let task = async move {
|
||||
let before = chrono::Local::now();
|
||||
eprintln!(" : [{}] {_namespace}::{_name} \tsending request...", before.format(TIMESTAMP_FMT));
|
||||
if _dry_run {
|
||||
(Ok("".to_string()), _namespace, _name, before)
|
||||
} else {
|
||||
let res = _endpoint
|
||||
.fill(&_env)
|
||||
.execute(&_client)
|
||||
.await;
|
||||
(res, _namespace, _name, before)
|
||||
}
|
||||
};
|
||||
if *parallel {
|
||||
pool.spawn(task);
|
||||
|
|
Loading…
Reference in a new issue