Skip to content

Commit

Permalink
Merge pull request #31 from bgpkit/load-env-file
Browse files Browse the repository at this point in the history
allow loading env file in cli
  • Loading branch information
digizeph authored Nov 28, 2023
2 parents 37a2919 + 1595b36 commit 5f828f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ indicatif = { version = "0.17.7", optional = true }
futures-util = { version = "0.3.28", optional = true }
itertools = { version = "0.12.0" , optional = true }
tempfile = "3.8"
dotenvy = { version = "0.15" , optional = true }

# crawler dependencies
futures = {version="0.3", optional = true}
Expand All @@ -65,7 +66,7 @@ sqlx = { version = "0.7", features = [ "runtime-tokio", "sqlite"], optional = tr
default=[]
cli = [
# command-line interface
"clap", "dirs", "humantime", "num_cpus", "tracing-subscriber", "tabled", "itertools",
"clap", "dirs", "humantime", "num_cpus", "tracing-subscriber", "tabled", "itertools", "dotenvy",
# crawler
"futures", "oneio", "regex", "scraper", "tokio", "lazy_static",
# database
Expand Down
15 changes: 15 additions & 0 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ struct Cli {
#[clap(long, global = true)]
no_log: bool,

#[clap(long, global = true)]
env: Option<String>,

#[clap(subcommand)]
command: Commands,
}
Expand Down Expand Up @@ -255,6 +258,18 @@ fn main() {

let do_log = !cli.no_log;

if let Some(env_path) = cli.env {
match dotenvy::from_path_override(env_path.as_str()) {
Ok(_) => {
info!("loaded environment variables from {}", env_path);
}
Err(_) => {
error!("failed to load environment variables from {}", env_path);
exit(1);
}
};
}

if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "bgpkit_broker=info,poem=debug");
}
Expand Down

0 comments on commit 5f828f4

Please sign in to comment.