Expand description
an (opinionated) app wrapper to eliminate main function boilerplate
Eliminate boilerplate by smartly integrating:
anyhow
: for easy error handlingclap
: for easy CLI parsingdotenv
: for easy environment variable managementtracing
: for easy logging
In lieu of main()
, an entrypoint
function is defined.
Perfectly reasonable setup/config is done automagically.
More explicitly, the entrypoint
function can be written as if:
anyhow::Error
is ready to propogate- CLI have been parsed
.dotenv
files have already been processed and populated into the environment- logging is ready to use
Customization can be achieved by overriding various trait default implementations (or preferably/more-typically by using the provided attribute macros).
§Examples
use entrypoint::prelude::*;
#[derive(clap::Parser, DotEnvDefault, LoggerDefault, Debug)]
#[log_format(pretty)]
#[log_level(entrypoint::LevelFilter::DEBUG)]
#[log_writer(std::io::stdout)]
struct Args {}
// this function replaces `main`
#[entrypoint::entrypoint]
fn main(args: Args) -> anyhow::Result<()> {
// tracing & parsed clap struct are ready-to-use
debug!("entrypoint input args: {:#?}", args);
// env vars already have values from dotenv file(s)
for (key, value) in std::env::vars() {
println!("{key}: {value}");
}
// easy error propagation w/ anyhow
Ok(())
}
§Feature Flags
Name | Description | Default? |
---|---|---|
macros | Enables optional utility macros | Yes |
Re-exports§
pub extern crate anyhow;
pub extern crate clap;
pub extern crate entrypoint_macros;
pub extern crate tracing;
pub extern crate tracing_subscriber;
pub use crate::prelude::*;
Modules§
- macros
- re-export
entrypoint_macros
- prelude
- essential traits and re-exports
Traits§
- DotEnv
Parser - blanket implementation for automatic
dotenv
processing - DotEnv
Parser Config - automatic
dotenv
processing configuration - Entrypoint
- blanket implementation to wrap a function with “
main()
” setup/initialization boilerplate - Logger
- blanket implementation for automatic
tracing
&tracing_subscriber
initialization - Logger
Config - automatic
tracing
&tracing_subscriber
configuration