documentation updates to the binaries

This commit is contained in:
Dietrich 2021-06-16 11:05:21 +02:00 committed by Franz Dietrich
parent f7f10c5577
commit f3b1a0d7e8
2 changed files with 10 additions and 2 deletions

View File

@ -20,6 +20,7 @@ use tracing::{error, info, trace, warn};
static MIGRATOR: Migrator = sqlx::migrate!(); static MIGRATOR: Migrator = sqlx::migrate!();
/// generate the commandline options available
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
fn generate_cli() -> App<'static, 'static> { fn generate_cli() -> App<'static, 'static> {
app_from_crate!() app_from_crate!()
@ -126,6 +127,7 @@ fn generate_cli() -> App<'static, 'static> {
) )
} }
/// parse the options to the [`ServerConfig`] struct
async fn parse_args_to_config(config: ArgMatches<'_>) -> ServerConfig { async fn parse_args_to_config(config: ArgMatches<'_>) -> ServerConfig {
let secret = config let secret = config
.value_of("secret") .value_of("secret")
@ -204,12 +206,16 @@ async fn parse_args_to_config(config: ArgMatches<'_>) -> ServerConfig {
} }
} }
/// Setup and launch the command
///
/// # Panics
/// This funcion panics if preconditions like the availability of the database are not met.
pub(crate) async fn setup() -> Result<Option<crate::ServerConfig>, ServerError> { pub(crate) async fn setup() -> Result<Option<crate::ServerConfig>, ServerError> {
// load the environment .env file if available.
dotenv().ok(); dotenv().ok();
// Print launch info // Print launch info
info!("Launching Pslink a 'Private short link generator'"); info!("Launching Pslink a 'Private short link generator'");
trace!("logging initialized");
let app = generate_cli(); let app = generate_cli();
@ -328,6 +334,7 @@ async fn create_admin(config: &ServerConfig) -> Result<(), ServerError> {
Ok(()) Ok(())
} }
/// Apply any pending migrations to the database. The migrations are embedded in the binary and don't need any addidtional files.
async fn apply_migrations(config: &ServerConfig) -> Result<(), ServerError> { async fn apply_migrations(config: &ServerConfig) -> Result<(), ServerError> {
info!( info!(
"Creating a database file and running the migrations in the file {}:", "Creating a database file and running the migrations in the file {}:",
@ -337,6 +344,7 @@ async fn apply_migrations(config: &ServerConfig) -> Result<(), ServerError> {
Ok(()) Ok(())
} }
/// The commandline parameters provided or if missing the default parameters can be converted and written to a .env file. That way the configuration is saved and automatically reused for subsequent launches.
fn generate_env_file(server_config: &ServerConfig) -> Result<(), ServerError> { fn generate_env_file(server_config: &ServerConfig) -> Result<(), ServerError> {
if std::path::Path::new(".env").exists() { if std::path::Path::new(".env").exists() {
return Err(ServerError::User( return Err(ServerError::User(

View File

@ -42,7 +42,7 @@ pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {
#[instrument] #[instrument]
#[actix_web::main] #[actix_web::main]
async fn main() -> std::result::Result<(), std::io::Error> { async fn main() -> std::result::Result<(), std::io::Error> {
let subscriber = get_subscriber("fhs.li", "info"); let subscriber = get_subscriber("pslink", "info");
init_subscriber(subscriber); init_subscriber(subscriber);
match cli::setup().await { match cli::setup().await {