on main help sign in
Use .env file for environment variables
a07979afabianlindfors
Cargo.toml+2−1
@@ -21,4 +21,5 @@ clap = { version = "3.0.14", features = ["derive"] }
21toml = "0.5"
21toml = "0.5"
22version = "3.0.0"
22version = "3.0.0"
23colored = "2"
23colored = "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
559
559
560### Connection options
560### Connection options
561
561
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.
563
565
564| Option | Default | Environment variable | Description |
566| Option | Default | Environment variable | Description |
565| ------ | ------- | -------------------- | ----------- |
567| ------ | ------- | -------------------- | ----------- |
src/main.rs+3
@@ -105,6 +105,9 @@ fn run(opts: Opts) -> anyhow::Result<()> {
105}
105}
106
106
107fn reshape_from_connection_options(opts: &ConnectionOptions) -> anyhow::Result<Reshape> {
107fn reshape_from_connection_options(opts: &ConnectionOptions) -> anyhow::Result<Reshape> {
108+ // Load environment variables from .env file if it exists
109+ dotenv::dotenv().ok();
110+
108 let url_env = std::env::var("DB_URL").ok();
111 let url_env = std::env::var("DB_URL").ok();
109 let url = url_env.as_ref().or_else(|| opts.url.as_ref());
112 let url = url_env.as_ref().or_else(|| opts.url.as_ref());
110
113