eliminate main function boilerplate with this opinionated application framework/wrapper
entrypoint
has the following design goals:
- eliminate application startup/configuration boilerplate
- help enforce application best practices
entrypoint
essentially wraps a user defined function with automatic configuration/setup/processing of:
- logging (via tracing
)
- command-line arguments (via clap
)
- .dotenv
file(s), environment variable population/overrides (via dotenvy
)
- easy application error handling (via anyhow
)
The user defined function is intended to be/replace main()
.
Thus, the main/entrypoint function can be written as if all the configuration/processing/boilerplate is ready-to-use.
More explicitly:
- clap::Parser
struct has been parsed & populated
- .dotenv
files have been parsed; environment variables are ready to go
- tracing
has been configured & the global subscriber has been registered
Using the default behavior is totally reasonable, but overwriting some traits' default impl(s) can provide customization.
Include the entrypoint
prelude:
rust
use entrypoint::prelude::*;
Define a clap
struct:
```rust
struct Args { #[arg(short, long)] debug: bool, } ```
Define an entrypoint/main function: ```rust
fn main(args: Args) -> entrypoint::anyhow::Result<()> { // env::vars() already loaded-from/merged-with .dotenv file(s) let devsecret = env::vars("SECRET_KEY");
// logging is ready to use
entrypoint::tracing::info!("entrypoint::entrypoint");
// args is already parsed and ready to use
entrypoint::tracing::info!("w/ {:#?}", args);
Ok(())
} ``` This function must:
clap::Parser
as an inputentrypoint::anyhow::Result<()>
Note: #[entrypoint::entrypoint]
should be first when used with other attribute macros.
e.g.:
```rust
async fn main(args: Args) -> entrypoint::anyhow::Result<()> { Ok(()) } ```
For more information, refer to: - docs.rs - tests
entrypoint
is divided into the following crates:
- entrypoint
: core traits & functionality
- entrypoint_macros
: convienence macros to further reduce boilerplate
Before doing anything else: open an issue.