feat: add list action (as default)

This commit is contained in:
əlemi 2024-10-19 21:53:47 +02:00
parent 58900630e1
commit 68a73284c7
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,5 +1,6 @@
mod model; mod model;
mod errors; mod errors;
mod ext;
use std::sync::Arc; use std::sync::Arc;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
@ -19,10 +20,10 @@ struct PostWomanArgs {
/// action to run /// action to run
#[clap(subcommand)] #[clap(subcommand)]
action: PostWomanActions, action: Option<PostWomanActions>,
} }
#[derive(Subcommand, Debug)] #[derive(Subcommand, Debug, Default)]
pub enum PostWomanActions { pub enum PostWomanActions {
/// execute specific endpoint requests /// execute specific endpoint requests
Run { Run {
@ -38,6 +39,10 @@ pub enum PostWomanActions {
repeat: u32, repeat: u32,
}, },
/// show all registered routes in current collection
#[default]
List,
// Save { // Save {
// /// name for new endpoint // /// name for new endpoint
// name: String, // name: String,
@ -69,7 +74,21 @@ async fn main() -> Result<(), PostWomanError> {
let collection = std::fs::read_to_string(args.collection)?; let collection = std::fs::read_to_string(args.collection)?;
let config: PostWomanConfig = toml::from_str(&collection)?; let config: PostWomanConfig = toml::from_str(&collection)?;
match args.action { match args.action.unwrap_or_default() {
PostWomanActions::List => {
let ua = config.client.user_agent.unwrap_or(APP_USER_AGENT.to_string());
println!("> {ua}");
for (key, value) in config.env {
println!("+ {key}: {}", ext::stringify_toml(&value));
}
println!();
for (name, endpoint) in config.route {
println!("- {name}: \t{} \t{}", endpoint.method.unwrap_or("GET".into()), endpoint.url);
}
},
PostWomanActions::Run { query, parallel, repeat } => { PostWomanActions::Run { query, parallel, repeat } => {
let pattern = regex::Regex::new(&query)?; let pattern = regex::Regex::new(&query)?;
let mut joinset = tokio::task::JoinSet::new(); let mut joinset = tokio::task::JoinSet::new();