diff --git a/crates/mollie_cli/src/balances/mod.rs b/crates/mollie_cli/src/balances/mod.rs index bd4c12c..383f2aa 100644 --- a/crates/mollie_cli/src/balances/mod.rs +++ b/crates/mollie_cli/src/balances/mod.rs @@ -10,24 +10,27 @@ mod list; #[derive(Parser)] #[clap(version, about)] pub struct BalancesCommand { + /// Enable debug logging #[clap(short, long, global = true)] debug: bool, + /// Print the API response after performing an API call #[clap(long = "withResponse", global = true)] with_response: bool, + #[clap(subcommand)] command: Option, } #[derive(Subcommand)] pub enum BalanceCommands { - /// Get a balance + /// Get information about a single balance (defaults to your primary balance) Get { #[clap(default_value = "primary")] id: String, }, - /// List balances + /// List and get information about all your balances List { #[clap(short, long)] limit: Option, diff --git a/crates/mollie_cli/src/main.rs b/crates/mollie_cli/src/main.rs index 8e46538..49a4fe5 100644 --- a/crates/mollie_cli/src/main.rs +++ b/crates/mollie_cli/src/main.rs @@ -29,13 +29,13 @@ struct Cli { #[derive(Subcommand)] enum Commands { - /// Do Auth things + /// Set up your authentication method for the Mollie API Auth(auth::AuthCommand), - /// Do Balance things + /// Get information about your balances Balances(balances::BalancesCommand), - /// Do Organizationy things + /// Get information about the organization you are authenticated as Org(org::OrgCommand), - /// Do things with Payments + /// Create, refund and get information about your payments Payments(payments::PaymentsCommmand), } diff --git a/crates/mollie_cli/src/payments/create.rs b/crates/mollie_cli/src/payments/create.rs index 9f6ac1b..868dec9 100644 --- a/crates/mollie_cli/src/payments/create.rs +++ b/crates/mollie_cli/src/payments/create.rs @@ -1,9 +1,10 @@ -use crate::config::MollieConfig; -use colored::Colorize; +use crate::{config::MollieConfig, payments::create}; use log::{debug, info, warn}; use mollie_api::Mollie; use requestty::Question; use serde::Serialize; +use colored::Colorize; +use colored_json::ToColoredJson; pub async fn command( config: &MollieConfig, @@ -13,6 +14,7 @@ pub async fn command( input_redirect_url: Option<&String>, input_profile_id: Option<&String>, debug: &bool, + with_request: bool, ) -> miette::Result<()> { debug!("Running Create Payment Command"); let currency = String::from(input_currency.unwrap()); @@ -36,8 +38,14 @@ pub async fn command( ask_confirmation(); } - let token = config.bearer_token()?; + debug!("{:?}", create_payment_request); + + if with_request { + let pretty_json = jsonxf::pretty_print(&serde_json::to_string(&create_payment_request).unwrap()).unwrap(); + info!("{}", pretty_json.to_colored_json_auto().unwrap()); + } + let token = config.bearer_token()?; let response = Mollie::build(&token.as_str()) .payments() .create_payment(&create_payment_request) @@ -51,7 +59,7 @@ pub async fn command( return Ok(()); } -pub async fn interactive(config: &MollieConfig, debug: &bool) -> miette::Result<()> { +pub async fn interactive(config: &MollieConfig, debug: &bool, with_request: bool) -> miette::Result<()> { debug!("Running interactive Create Payment Command"); // Currency @@ -75,6 +83,11 @@ pub async fn interactive(config: &MollieConfig, debug: &bool) -> miette::Result< profile_id, }; + if with_request { + let pretty_json = jsonxf::pretty_print(&serde_json::to_string(&create_payment_request).unwrap()).unwrap(); + info!("{}", pretty_json.to_colored_json_auto().unwrap()); + } + if debug == &true { let json = serde_json::to_string(&create_payment_request).unwrap(); debug!("Request Body: {:?}", json); diff --git a/crates/mollie_cli/src/payments/mod.rs b/crates/mollie_cli/src/payments/mod.rs index f0739bf..d556e9c 100644 --- a/crates/mollie_cli/src/payments/mod.rs +++ b/crates/mollie_cli/src/payments/mod.rs @@ -20,6 +20,9 @@ pub struct PaymentsCommmand { #[clap(long = "withResponse", global = true)] with_response: bool, + #[clap(long = "withRequest", global = true)] + with_request: bool, + #[clap(subcommand)] command: Option, } @@ -45,20 +48,23 @@ pub enum PaymentsCommands { #[clap(short, long)] interactive: bool, - #[clap(long)] + #[clap(long, required_unless_present("interactive"))] currency: Option, - #[clap(long)] + #[clap(long, required_unless_present("interactive"))] amount: Option, - #[clap(long)] + #[clap(long, required_unless_present("interactive"))] description: Option, - #[clap(long)] + #[clap(long, required_unless_present("interactive"))] redirect_url: Option, - #[clap(long)] + #[clap(long, required_unless_present("interactive"))] profile_id: Option, + + #[clap(long = "withRequest", global = true)] + with_request: bool, }, /// Get a payment's info #[clap(arg_required_else_help(true))] @@ -107,10 +113,11 @@ pub async fn command( description, redirect_url, profile_id, + with_request, }) => { match interactive { true => { - return create::interactive(config, debug).await; + return create::interactive(config, debug, *with_request).await; } false => {} } @@ -123,6 +130,7 @@ pub async fn command( redirect_url.as_ref(), profile_id.as_ref(), debug, + *with_request, ) .await?; }