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

PXP-445: [CLI] Printing DEBUG log from the CLI #52

Merged
merged 1 commit into from
Jan 9, 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lto = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4", features = ["derive", "wrap_help"] }
clap = { version = "4", features = ["derive", "wrap_help", "cargo"] }
clap_complete = { version = "4" }
dirs = "4.0"
indicatif = "0.17.0"
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/application.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::QueryClient;
use crate::error::APIError;
use graphql_client::{GraphQLQuery, Response};
use log::debug;

#[derive(GraphQLQuery)]
#[graphql(
Expand All @@ -25,6 +26,8 @@ impl ApplicationsQuery {
})
.await?;

debug!("response: {:?}", &response);

Ok(response)
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/changelog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::QueryClient;
use crate::error::APIError;
use graphql_client::{GraphQLQuery, Response};
use log::debug;

#[derive(GraphQLQuery)]
#[graphql(
Expand Down Expand Up @@ -46,6 +47,8 @@ impl ChangelogsQuery {
})
.await?;

debug!("response: {:?}", &response);

Ok(response)
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/graphql/deployment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::QueryClient;
use crate::error::APIError;
use graphql_client::{GraphQLQuery, Response};
use log::debug;

#[derive(GraphQLQuery)]
#[graphql(
Expand Down Expand Up @@ -32,6 +33,8 @@ impl CdPipelinesQuery {
})
.await?;

debug!("response: {:?}", &response);

Ok(response)
}
}
Expand Down Expand Up @@ -70,6 +73,8 @@ impl CdPipelineQuery {
})
.await?;

debug!("response: {:?}", &response);

Ok(response)
}
}
Expand Down Expand Up @@ -118,6 +123,8 @@ impl ExecuteCdPipeline {
})
.await?;

debug!("response: {:?}", &response);

Ok(response)
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use crate::{
error::APIError,
telemetry::{self, TelemetryData, TelemetryEvent},
};
use graphql_client::{reqwest::post_graphql, GraphQLQuery, Response};
use graphql_client::{GraphQLQuery, Response};
use log::debug;
use reqwest::header;
use wukong_telemetry_macro::wukong_telemetry;

Expand Down Expand Up @@ -102,7 +103,13 @@ impl QueryClient {
graphql_client::Error,
) -> Result<Response<Q::ResponseData>, APIError>,
) -> Result<Response<Q::ResponseData>, APIError> {
let response = post_graphql::<Q, _>(self.inner(), &self.api_url, variables).await?;
let body = Q::build_query(variables);
let request = self.inner().post(&self.api_url).json(&body);

debug!("request: {:?}", request);
debug!("graphQL query: \n{}", body.query);

let response: Response<Q::ResponseData> = request.send().await?.json().await?;

if let Some(errors) = response.errors.clone() {
let first_error = errors[0].clone();
Expand Down
9 changes: 9 additions & 0 deletions src/graphql/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::QueryClient;
use crate::error::APIError;
use graphql_client::{GraphQLQuery, Response};
use log::debug;

#[derive(GraphQLQuery)]
#[graphql(
Expand Down Expand Up @@ -38,6 +39,8 @@ impl PipelinesQuery {
})
.await?;

debug!("response: {:?}", &response);

Ok(response)
}
}
Expand Down Expand Up @@ -75,6 +78,8 @@ impl PipelineQuery {
})
.await?;

debug!("response: {:?}", &response);

Ok(response)
}
}
Expand Down Expand Up @@ -112,6 +117,8 @@ impl MultiBranchPipelineQuery {
})
.await?;

debug!("response: {:?}", &response);

Ok(response)
}
}
Expand Down Expand Up @@ -148,6 +155,8 @@ impl CiStatusQuery {
})
.await?;

debug!("response: {:?}", &response);

Ok(response)
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ mod telemetry;
use crate::auth::refresh_tokens;
use app::{App, ConfigState};
use chrono::{DateTime, Local};
use clap::crate_version;
use commands::{
completion::handle_completion, init::handle_init, login::handle_login, CommandGroup,
};
use config::{AuthConfig, Config, CONFIG_FILE};
use error::CliError;
use human_panic::setup_panic;
use log::{error, info};
use log::{debug, error, info};
use openidconnect::RefreshToken;
use output::error::ErrorOutput;
use std::process;
Expand Down Expand Up @@ -153,6 +154,18 @@ async fn run() -> Result<bool, CliError> {
context.application = Some(application.clone());
}

debug!("current cli version: {}", crate_version!());
debug!("current application: {:?}", &context.application);
debug!(
"current API URL: {:?}",
match &app.config {
ConfigState::InitialisedButUnAuthenticated(config)
| ConfigState::InitialisedAndAuthenticated(config) => Some(&config.core.wukong_api_url),
ConfigState::Uninitialised => None,
}
);
debug!("current calling user: {:?}", &context.account);

match app.cli.command_group {
CommandGroup::Pipeline(pipeline) => {
must_init_and_login!(app.config, pipeline.handle_command(context).await)
Expand Down