documentation updates to the binaries
This commit is contained in:
parent
f7f10c5577
commit
f3b1a0d7e8
@ -20,6 +20,7 @@ use tracing::{error, info, trace, warn};
|
||||
|
||||
static MIGRATOR: Migrator = sqlx::migrate!();
|
||||
|
||||
/// generate the commandline options available
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn generate_cli() -> App<'static, 'static> {
|
||||
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 {
|
||||
let secret = config
|
||||
.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> {
|
||||
// load the environment .env file if available.
|
||||
dotenv().ok();
|
||||
|
||||
// Print launch info
|
||||
info!("Launching Pslink a 'Private short link generator'");
|
||||
trace!("logging initialized");
|
||||
|
||||
let app = generate_cli();
|
||||
|
||||
@ -328,6 +334,7 @@ async fn create_admin(config: &ServerConfig) -> Result<(), ServerError> {
|
||||
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> {
|
||||
info!(
|
||||
"Creating a database file and running the migrations in the file {}:",
|
||||
@ -337,6 +344,7 @@ async fn apply_migrations(config: &ServerConfig) -> Result<(), ServerError> {
|
||||
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> {
|
||||
if std::path::Path::new(".env").exists() {
|
||||
return Err(ServerError::User(
|
||||
|
@ -42,7 +42,7 @@ pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {
|
||||
#[instrument]
|
||||
#[actix_web::main]
|
||||
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);
|
||||
|
||||
match cli::setup().await {
|
||||
|
Loading…
Reference in New Issue
Block a user