Add CLI command for generating OpenAPI documentation
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
mod cmd;
|
||||
mod configs;
|
||||
mod errors;
|
||||
mod middlewares;
|
||||
@@ -21,15 +22,39 @@ use crate::{
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Temporary subscriber for initial logging during configuration reading
|
||||
let make_temporary_subscriber = || {
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
.with_target(false)
|
||||
.with_level(true)
|
||||
.finish()
|
||||
};
|
||||
// only run command line interface if arguments are provided
|
||||
if std::env::args().len() > 1 {
|
||||
process_commands().await;
|
||||
return;
|
||||
}
|
||||
|
||||
start_server().await;
|
||||
}
|
||||
|
||||
async fn process_commands() {
|
||||
tracing::subscriber::with_default(make_temporary_subscriber(), async || {
|
||||
use clap::error::ErrorKind;
|
||||
|
||||
let mut command = cmd::get_command();
|
||||
let help_output = format!("{}", command.render_help());
|
||||
let matches = command
|
||||
.try_get_matches()
|
||||
.unwrap_or_else(|err| match err.kind() {
|
||||
ErrorKind::DisplayHelp | ErrorKind::DisplayVersion => {
|
||||
err.print().expect("Error writing Error");
|
||||
std::process::exit(0);
|
||||
}
|
||||
_ => {
|
||||
err.print().expect("Error writing Error");
|
||||
std::process::exit(1);
|
||||
}
|
||||
});
|
||||
cmd::execute(&matches, &help_output).await;
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
async fn start_server() {
|
||||
let settings =
|
||||
tracing::subscriber::with_default(make_temporary_subscriber(), || -> ProgramSettings {
|
||||
debug!("Temporary subscriber installed.");
|
||||
@@ -86,6 +111,14 @@ async fn main() {
|
||||
.expect("Failed to run the server");
|
||||
}
|
||||
|
||||
fn make_temporary_subscriber() -> tracing_subscriber::fmt::Subscriber {
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
.with_target(false)
|
||||
.with_level(true)
|
||||
.finish()
|
||||
}
|
||||
|
||||
fn get_global_tracing_subscriber_builder(
|
||||
settings: &LoggingSettings,
|
||||
) -> tracing_subscriber::fmt::SubscriberBuilder<
|
||||
|
||||
Reference in New Issue
Block a user