on main help sign in
Use .env file for environment variables
commita07979a97a7e506ffbc375d62071efadbd273cc5 authorfabianlindfors <fabian@flapplabs.se> dateThu 3 Feb 2022, 23:57 (5 years ago) parent8129fdb
3 files changed+8−2
Cargo.toml+2−1 README.md+3−1 src/main.rs+3
Cargo.toml+2−1
@@ -21,4 +21,5 @@ clap = { version = "3.0.14", features = ["derive"] }
2121toml = "0.5"
2222version = "3.0.0"
2323colored = "2"
24−rand = "0.8"
24+rand = "0.8"
25+dotenv = "0.15.0"
README.md+3−1
@@ -559,7 +559,9 @@ The query should look something like `SET search_path TO migration_1_initial_mig
559559
560560### Connection options
561561
562−The options below can be used with all commands that communicate with Postgres. Use either a [connection URL](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING) or specify each connection option individually. All options can also be set using environment variables instead of flags.
562+The options below can be used with all commands that communicate with Postgres. Use either a [connection URL](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING) or specify each connection option individually.
563+
564+All options can also be set using environment variables instead of flags. If a `.env` file exists, then variables will be automatically loaded from there.
563565
564566| Option | Default | Environment variable | Description |
565567| ------ | ------- | -------------------- | ----------- |
src/main.rs+3
@@ -105,6 +105,9 @@ fn run(opts: Opts) -> anyhow::Result<()> {
105105}
106106
107107fn reshape_from_connection_options(opts: &ConnectionOptions) -> anyhow::Result<Reshape> {
108+ // Load environment variables from .env file if it exists
109+ dotenv::dotenv().ok();
110+
108111 let url_env = std::env::var("DB_URL").ok();
109112 let url = url_env.as_ref().or_else(|| opts.url.as_ref());
110113