entrypoint 0.1.1

opinionated application framework/wrapper that eliminates main function boilerplate
Documentation

entrypoint

Crates.io Crates.io Documentation License

eliminate main function boilerplate with this opinionated application framework/wrapper

About

entrypoint has the following design goals:

  • eliminate application startup/configuration boilerplate
  • help enforce application best practices

What does this crate actually do?

entrypoint wraps a user defined function with automatic configuration/setup/processing of:

  • logging (via tracing)
  • command-line argument parsing (via clap)
  • .dotenv file processing and environment variable population/overrides (via dotenvy)
  • easy application error handling (via anyhow)

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:

  • clap::Parser struct has been parsed and populated
  • .dotenv files have been parsed; environment variables are ready to go
  • tracing has been configured and the global subscriber has been registered

Usage

Default Config

  1. Include the entrypoint prelude:

    use entrypoint::prelude::*;
    
  2. Define a clap struct and derive default entrypoint trait impls:

    #[derive(clap::Parser, DotEnvDefault, LoggerDefault, Debug)]
    #[log_level(entrypoint::tracing::Level::DEBUG)]
    #[command(version, about, long_about = None)]
    struct Args {
        #[arg(short, long)]
        verbose: bool,
    }
    
  3. Define an entrypoint/main function:

    #[entrypoint::entrypoint]
    fn entrypoint(args: Args) -> entrypoint::anyhow::Result<()> {
        // 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");
    
        // args is already parsed and ready to use
        info!("verbose set to: {:?}", args.verbose);
    
        Ok(())
    }
    

Custom Config

Using the default behavior is totally reasonable, but overwriting some trait default impl(s) can provide customization.

Usage Notes

  1. The entrypoint function must:
    1. Accept a clap::Parser as an input.
    2. Return entrypoint::anyhow::Result<()>.
  2. #[entrypoint::entrypoint] ordering may matter when used with other attribute macros.

Documentation

For more information, refer to:

Crates

entrypoint is divided into the following crates:

Contributing

Before doing anything else: open an issue.