Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pietro/dx changes #17

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions crates/mollie_cli/src/balances/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BalanceCommands>,
}

#[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<i32>,
Expand Down
8 changes: 4 additions & 4 deletions crates/mollie_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down
21 changes: 17 additions & 4 deletions crates/mollie_cli/src/payments/create.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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());
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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);
Expand Down
20 changes: 14 additions & 6 deletions crates/mollie_cli/src/payments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PaymentsCommands>,
}
Expand All @@ -45,20 +48,23 @@ pub enum PaymentsCommands {
#[clap(short, long)]
interactive: bool,

#[clap(long)]
#[clap(long, required_unless_present("interactive"))]
currency: Option<String>,

#[clap(long)]
#[clap(long, required_unless_present("interactive"))]
amount: Option<String>,

#[clap(long)]
#[clap(long, required_unless_present("interactive"))]
description: Option<String>,

#[clap(long)]
#[clap(long, required_unless_present("interactive"))]
redirect_url: Option<String>,

#[clap(long)]
#[clap(long, required_unless_present("interactive"))]
profile_id: Option<String>,

#[clap(long = "withRequest", global = true)]
with_request: bool,
},
/// Get a payment's info
#[clap(arg_required_else_help(true))]
Expand Down Expand Up @@ -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 => {}
}
Expand All @@ -123,6 +130,7 @@ pub async fn command(
redirect_url.as_ref(),
profile_id.as_ref(),
debug,
*with_request,
)
.await?;
}
Expand Down
Loading