diff --git a/omdb/src/bin/omdb/db.rs b/omdb/src/bin/omdb/db.rs index f54a377600..e032442f68 100644 --- a/omdb/src/bin/omdb/db.rs +++ b/omdb/src/bin/omdb/db.rs @@ -42,7 +42,8 @@ use uuid::Uuid; #[derive(Debug, Args)] pub struct DbArgs { /// URL of the database SQL interface - db_url: PostgresConfigWithUrl, + #[clap(long, env("OMDB_DB_URL"))] + db_url: Option, /// limit to apply to queries that fetch rows #[clap( @@ -126,7 +127,15 @@ impl DbArgs { &self, log: &slog::Logger, ) -> Result<(), anyhow::Error> { - let db_config = db::Config { url: self.db_url.clone() }; + // This is a little goofy. The database URL is required, but can come + // from the environment, in which case it won't be on the command line. + let Some(db_url) = &self.db_url else { + bail!( + "database URL must be specified with --db-url or OMDB_DB_URL" + ); + }; + + let db_config = db::Config { url: db_url.clone() }; let pool = Arc::new(db::Pool::new(&log.clone(), &db_config)); // Being a dev tool, we want to try this operation even if the schema diff --git a/omdb/src/bin/omdb/nexus.rs b/omdb/src/bin/omdb/nexus.rs index 53c936cb95..07003269fd 100644 --- a/omdb/src/bin/omdb/nexus.rs +++ b/omdb/src/bin/omdb/nexus.rs @@ -4,6 +4,7 @@ //! omdb commands that query or update specific Nexus instances +use anyhow::bail; use anyhow::Context; use chrono::SecondsFormat; use chrono::Utc; @@ -22,7 +23,8 @@ use uuid::Uuid; #[derive(Debug, Args)] pub struct NexusArgs { /// URL of the Nexus internal API - nexus_internal_url: String, + #[clap(long, env("OMDB_NEXUS_URL"))] + nexus_internal_url: Option, #[command(subcommand)] command: NexusCommands, @@ -57,8 +59,15 @@ impl NexusArgs { &self, log: &slog::Logger, ) -> Result<(), anyhow::Error> { - let client = - nexus_client::Client::new(&self.nexus_internal_url, log.clone()); + // This is a little goofy. The database URL is required, but can come + // from the environment, in which case it won't be on the command line. + let Some(nexus_url) = &self.nexus_internal_url else { + bail!( + "nexus URL must be specified with --nexus-internal-url or \ + OMDB_NEXUS_URL" + ); + }; + let client = nexus_client::Client::new(nexus_url, log.clone()); match &self.command { NexusCommands::BackgroundTask(BackgroundTaskArgs {