Skip to content

Commit

Permalink
verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
tapans committed Dec 17, 2024
1 parent 0c9f91f commit 82cd8b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl ApiClient {
}
}

pub async fn build_request(
pub async fn build_request(
&self,
method: &str,
endpoint: &str,
Expand Down Expand Up @@ -178,14 +178,20 @@ impl ApiClient {
data: Option<&str>,
auth_type: Option<&str>,
username: Option<&str>,
verbose: bool,
) -> Result<serde_json::Value, Error> {
let request_builder = self
.build_request(method, endpoint, headers, data, auth_type, username)
.await?;


let req = request_builder.try_clone().unwrap().build()?;
let response = request_builder.send().await?;

if verbose {
println!("Request: {:#?}", req);
println!("Response: {:#?}", response)
}

let status = response.status();

match response.json::<serde_json::Value>().await {
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ pub struct Cli {
/// Username for OAuth2 authentication
#[arg(short, long)]
pub username: Option<String>,

/// Print verbose information
#[arg(short, long)]
pub verbose: bool,
}

#[derive(Subcommand)]
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async fn main() -> Result<(), Error> {
cli.data.as_deref(),
cli.auth.as_deref(),
cli.username.as_deref(),
cli.verbose,
)
.await {
Ok(res) => res,
Expand Down

0 comments on commit 82cd8b1

Please sign in to comment.