| Crates.io | entrypoint |
| lib.rs | entrypoint |
| version | 0.2.0 |
| created_at | 2023-09-20 17:40:08.719204+00 |
| updated_at | 2024-02-22 13:01:01.201264+00 |
| description | opinionated application framework/wrapper that eliminates main function boilerplate |
| homepage | https://github.com/melloyawn/entrypoint |
| repository | https://github.com/melloyawn/entrypoint |
| max_upload_size | |
| id | 978379 |
| size | 59,714 |
eliminate main function boilerplate with this opinionated application framework/wrapper
entrypoint has the following design goals:
entrypoint wraps a user defined function with automatic configuration/setup/processing of:
anyhow)clap).dotenv file processing and environment variable population/overrides (via dotenvy)tracing)The user defined function is intended to be/replace main().
Meaning, this main/entrypoint function can be written as if all the configuration/processing/boilerplate is ready-to-use. More explicitly:
anyhow is available and ready to useclap::Parser struct has been parsed and populated.dotenv files have been parsed; environment variables are ready to gotracing has been configured and the global subscriber has been registeredentrypoint was as much about deploying my first crate as anything else.
Turns out, it's really not that useful. I kind of think it's better just to explicitly set this stuff up in your application. The juice isn't work the squeeze.
It's unlikely further development will occur.
Include the entrypoint prelude:
use entrypoint::prelude::*;
Define a clap struct and derive default entrypoint trait impls:
#[derive(clap::Parser, DotEnvDefault, LoggerDefault, Debug)]
#[log_format(full)]
#[log_level(entrypoint::tracing::Level::INFO)]
#[command(version, about, long_about = None)]
struct CLIArgs {
#[arg(short, long, env)]
cli_arg: bool,
}
Define an entrypoint/main function:
#[entrypoint::entrypoint]
fn entrypoint(args: CLIArgs) -> entrypoint::anyhow::Result<()> {
// args are parsed and ready to use
info!("cli_arg set to: {:?}", args.cli_arg);
// env::vars() already loaded-from/merged-with .dotenv file(s)
let _my_var = env::vars("SOMETHING_FROM_DOTENV_FILE");
// logging is ready to use
info!("entrypoint::entrypoint");
Ok(())
}
Using the default behavior is totally reasonable, but overwriting some default impl(s) can provide customization.
entrypoint function must:
clap::Parser input parameterentrypoint::anyhow::Result<()>#[entrypoint::entrypoint] ordering may matter when used with other attribute macros (e.g. [tokio::main]).For more information, refer to:
entrypoint is divided into the following crates:
entrypoint: core traits and functionalityentrypoint_macros: convienence macros to further reduce boilerplateBefore doing anything else: open an issue.