diff --git a/dev-tools/omdb/src/bin/omdb/crucible_agent.rs b/dev-tools/omdb/src/bin/omdb/crucible_agent.rs index e2fd316335..b5c36e0b3d 100644 --- a/dev-tools/omdb/src/bin/omdb/crucible_agent.rs +++ b/dev-tools/omdb/src/bin/omdb/crucible_agent.rs @@ -12,13 +12,19 @@ use crucible_agent_client::types::RegionId; use crucible_agent_client::Client; use tabled::Tabled; +use crate::helpers::CONNECTION_OPTIONS_HEADING; use crate::Omdb; /// Arguments to the "omdb crucible-agent" subcommand #[derive(Debug, Args)] pub struct CrucibleAgentArgs { /// URL of the crucible agent internal API - #[clap(long, env("OMDB_CRUCIBLE_AGENT_URL"))] + #[clap( + long, + env = "OMDB_CRUCIBLE_AGENT_URL", + global = true, + help_heading = CONNECTION_OPTIONS_HEADING, + )] crucible_agent_url: Option, #[command(subcommand)] diff --git a/dev-tools/omdb/src/bin/omdb/db.rs b/dev-tools/omdb/src/bin/omdb/db.rs index 5930788cd2..0bbb232d55 100644 --- a/dev-tools/omdb/src/bin/omdb/db.rs +++ b/dev-tools/omdb/src/bin/omdb/db.rs @@ -15,6 +15,8 @@ // NOTE: emanates from Tabled macros #![allow(clippy::useless_vec)] +use crate::helpers::CONNECTION_OPTIONS_HEADING; +use crate::helpers::DATABASE_OPTIONS_HEADING; use crate::Omdb; use anyhow::anyhow; use anyhow::bail; @@ -163,7 +165,12 @@ pub struct DbArgs { #[derive(Debug, Args)] pub struct DbUrlOptions { /// URL of the database SQL interface - #[clap(long, env("OMDB_DB_URL"))] + #[clap( + long, + env = "OMDB_DB_URL", + global = true, + help_heading = CONNECTION_OPTIONS_HEADING, + )] db_url: Option, } @@ -231,13 +238,20 @@ pub struct DbFetchOptions { #[clap( long = "fetch-limit", default_value_t = NonZeroU32::new(500).unwrap(), - env("OMDB_FETCH_LIMIT"), + env = "OMDB_FETCH_LIMIT", + global = true, + help_heading = DATABASE_OPTIONS_HEADING, )] fetch_limit: NonZeroU32, /// whether to include soft-deleted records when enumerating objects that /// can be soft-deleted - #[clap(long, default_value_t = false)] + #[clap( + long, + default_value_t = false, + global = true, + help_heading = DATABASE_OPTIONS_HEADING, + )] include_deleted: bool, } @@ -413,7 +427,7 @@ struct NetworkArgs { command: NetworkCommands, /// Print out raw data structures from the data store. - #[clap(long)] + #[clap(long, global = true)] verbose: bool, } diff --git a/dev-tools/omdb/src/bin/omdb/helpers.rs b/dev-tools/omdb/src/bin/omdb/helpers.rs new file mode 100644 index 0000000000..f436340a38 --- /dev/null +++ b/dev-tools/omdb/src/bin/omdb/helpers.rs @@ -0,0 +1,9 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +//! Utility helpers for the omdb CLI. + +pub(crate) const CONNECTION_OPTIONS_HEADING: &str = "Connection Options"; +pub(crate) const DATABASE_OPTIONS_HEADING: &str = "Database Options"; +pub(crate) const SAFETY_OPTIONS_HEADING: &str = "Safety Options"; diff --git a/dev-tools/omdb/src/bin/omdb/main.rs b/dev-tools/omdb/src/bin/omdb/main.rs index ecf70dc11d..7469e2ba54 100644 --- a/dev-tools/omdb/src/bin/omdb/main.rs +++ b/dev-tools/omdb/src/bin/omdb/main.rs @@ -46,6 +46,7 @@ use tokio::net::TcpSocket; mod crucible_agent; mod db; +mod helpers; mod mgs; mod nexus; mod oximeter; @@ -84,14 +85,25 @@ struct Omdb { long, value_parser = parse_dropshot_log_level, default_value = "warn", + global = true, )] log_level: dropshot::ConfigLoggingLevel, - #[arg(env = "OMDB_DNS_SERVER", long)] + #[arg( + long, + env = "OMDB_DNS_SERVER", + global = true, + help_heading = helpers::CONNECTION_OPTIONS_HEADING, + )] dns_server: Option, /// Allow potentially-destructive subcommands. - #[arg(short = 'w', long = "destructive")] + #[arg( + short = 'w', + long = "destructive", + global = true, + help_heading = helpers::SAFETY_OPTIONS_HEADING, + )] allow_destructive: bool, #[command(subcommand)] diff --git a/dev-tools/omdb/src/bin/omdb/mgs.rs b/dev-tools/omdb/src/bin/omdb/mgs.rs index cef3ff2a2c..7f33d5de15 100644 --- a/dev-tools/omdb/src/bin/omdb/mgs.rs +++ b/dev-tools/omdb/src/bin/omdb/mgs.rs @@ -4,6 +4,7 @@ //! Prototype code for collecting information from systems in the rack +use crate::helpers::CONNECTION_OPTIONS_HEADING; use crate::Omdb; use anyhow::Context; use clap::Args; @@ -32,7 +33,12 @@ use sensors::SensorsArgs; #[derive(Debug, Args)] pub struct MgsArgs { /// URL of an MGS instance to query - #[clap(long, env("OMDB_MGS_URL"))] + #[clap( + long, + env = "OMDB_MGS_URL", + global = true, + help_heading = CONNECTION_OPTIONS_HEADING, + )] mgs_url: Option, #[command(subcommand)] diff --git a/dev-tools/omdb/src/bin/omdb/nexus.rs b/dev-tools/omdb/src/bin/omdb/nexus.rs index 60925d0cb4..1a12cbdf35 100644 --- a/dev-tools/omdb/src/bin/omdb/nexus.rs +++ b/dev-tools/omdb/src/bin/omdb/nexus.rs @@ -6,6 +6,7 @@ use crate::check_allow_destructive::DestructiveOperationToken; use crate::db::DbUrlOptions; +use crate::helpers::CONNECTION_OPTIONS_HEADING; use crate::Omdb; use anyhow::bail; use anyhow::Context; @@ -45,7 +46,12 @@ use uuid::Uuid; #[derive(Debug, Args)] pub struct NexusArgs { /// URL of the Nexus internal API - #[clap(long, env("OMDB_NEXUS_URL"))] + #[clap( + long, + env = "OMDB_NEXUS_URL", + global = true, + help_heading = CONNECTION_OPTIONS_HEADING, + )] nexus_internal_url: Option, #[command(subcommand)] diff --git a/dev-tools/omdb/src/bin/omdb/oximeter.rs b/dev-tools/omdb/src/bin/omdb/oximeter.rs index 29491bb083..573a91a093 100644 --- a/dev-tools/omdb/src/bin/omdb/oximeter.rs +++ b/dev-tools/omdb/src/bin/omdb/oximeter.rs @@ -4,6 +4,7 @@ //! omdb commands that query oximeter +use crate::helpers::CONNECTION_OPTIONS_HEADING; use anyhow::Context; use clap::Args; use clap::Subcommand; @@ -20,7 +21,14 @@ use uuid::Uuid; #[derive(Debug, Args)] pub struct OximeterArgs { /// URL of the oximeter collector to query - #[arg(long, env("OMDB_OXIMETER_URL"))] + #[arg( + long, + env = "OMDB_OXIMETER_URL", + // This can't be global = true (i.e. passed in later in the + // command-line) because global options can't be required. If this + // changes to being optional, we should set global = true. + help_heading = CONNECTION_OPTIONS_HEADING, + )] oximeter_url: String, #[command(subcommand)] diff --git a/dev-tools/omdb/src/bin/omdb/sled_agent.rs b/dev-tools/omdb/src/bin/omdb/sled_agent.rs index 2d9e19d253..9a9a17eff4 100644 --- a/dev-tools/omdb/src/bin/omdb/sled_agent.rs +++ b/dev-tools/omdb/src/bin/omdb/sled_agent.rs @@ -4,6 +4,7 @@ //! omdb commands that query or update specific Sleds +use crate::helpers::CONNECTION_OPTIONS_HEADING; use crate::Omdb; use anyhow::bail; use anyhow::Context; @@ -14,7 +15,12 @@ use clap::Subcommand; #[derive(Debug, Args)] pub struct SledAgentArgs { /// URL of the Sled internal API - #[clap(long, env("OMDB_SLED_AGENT_URL"))] + #[clap( + long, + env = "OMDB_SLED_AGENT_URL", + global = true, + help_heading = CONNECTION_OPTIONS_HEADING, + )] sled_agent_url: Option, #[command(subcommand)] diff --git a/dev-tools/omdb/tests/usage_errors.out b/dev-tools/omdb/tests/usage_errors.out index ee32167290..3ffe579a23 100644 --- a/dev-tools/omdb/tests/usage_errors.out +++ b/dev-tools/omdb/tests/usage_errors.out @@ -18,10 +18,14 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --log-level log level filter [env: LOG_LEVEL=] [default: warn] + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help (see more with '--help') + +Connection Options: --dns-server [env: OMDB_DNS_SERVER=] - -w, --destructive Allow potentially-destructive subcommands - -h, --help Print help (see more with '--help') + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["--help"] termination: Exited(0) @@ -50,14 +54,16 @@ Options: [env: LOG_LEVEL=] [default: warn] + -h, --help + Print help (see a summary with '-h') + +Connection Options: --dns-server [env: OMDB_DNS_SERVER=] +Safety Options: -w, --destructive Allow potentially-destructive subcommands - - -h, --help - Print help (see a summary with '-h') --------------------------------------------- stderr: ============================================= @@ -109,12 +115,21 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --db-url URL of the database SQL interface [env: OMDB_DB_URL=] + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --db-url URL of the database SQL interface [env: OMDB_DB_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Database Options: --fetch-limit limit to apply to queries that fetch rows [env: OMDB_FETCH_LIMIT=] [default: 500] --include-deleted whether to include soft-deleted records when enumerating objects that can be soft-deleted - -h, --help Print help + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["db", "--help"] termination: Exited(0) @@ -138,12 +153,21 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --db-url URL of the database SQL interface [env: OMDB_DB_URL=] + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --db-url URL of the database SQL interface [env: OMDB_DB_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Database Options: --fetch-limit limit to apply to queries that fetch rows [env: OMDB_FETCH_LIMIT=] [default: 500] --include-deleted whether to include soft-deleted records when enumerating objects that can be soft-deleted - -h, --help Print help + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands --------------------------------------------- stderr: ============================================= @@ -155,7 +179,7 @@ stdout: stderr: Print information about disks -Usage: omdb db disks +Usage: omdb db disks [OPTIONS] Commands: info Get info for a specific disk @@ -164,7 +188,21 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --db-url URL of the database SQL interface [env: OMDB_DB_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Database Options: + --fetch-limit limit to apply to queries that fetch rows [env: + OMDB_FETCH_LIMIT=] [default: 500] + --include-deleted whether to include soft-deleted records when enumerating objects + that can be soft-deleted + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["db", "dns"] termination: Exited(2) @@ -174,7 +212,7 @@ stdout: stderr: Print information about internal and external DNS -Usage: omdb db dns +Usage: omdb db dns [OPTIONS] Commands: show Summarize current version of all DNS zones @@ -183,7 +221,21 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --db-url URL of the database SQL interface [env: OMDB_DB_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Database Options: + --fetch-limit limit to apply to queries that fetch rows [env: + OMDB_FETCH_LIMIT=] [default: 500] + --include-deleted whether to include soft-deleted records when enumerating objects + that can be soft-deleted + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["db", "dns", "diff"] termination: Exited(2) @@ -234,8 +286,37 @@ Options: - reservation-create: Sleds on which reservations can be created - vpc-firewall: Sleds which should be sent VPC firewall rules + --log-level + log level filter + + [env: LOG_LEVEL=] + [default: warn] + -h, --help Print help (see a summary with '-h') + +Connection Options: + --db-url + URL of the database SQL interface + + [env: OMDB_DB_URL=] + + --dns-server + [env: OMDB_DNS_SERVER=] + +Database Options: + --fetch-limit + limit to apply to queries that fetch rows + + [env: OMDB_FETCH_LIMIT=] + [default: 500] + + --include-deleted + whether to include soft-deleted records when enumerating objects that can be soft-deleted + +Safety Options: + -w, --destructive + Allow potentially-destructive subcommands --------------------------------------------- stderr: ============================================= @@ -247,7 +328,7 @@ stdout: stderr: Print information about snapshots -Usage: omdb db snapshots +Usage: omdb db snapshots [OPTIONS] Commands: info Get info for a specific snapshot @@ -255,7 +336,21 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --db-url URL of the database SQL interface [env: OMDB_DB_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Database Options: + --fetch-limit limit to apply to queries that fetch rows [env: + OMDB_FETCH_LIMIT=] [default: 500] + --include-deleted whether to include soft-deleted records when enumerating objects + that can be soft-deleted + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["db", "network"] termination: Exited(2) @@ -273,8 +368,22 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --verbose Print out raw data structures from the data store - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + --verbose Print out raw data structures from the data store + -h, --help Print help + +Connection Options: + --db-url URL of the database SQL interface [env: OMDB_DB_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Database Options: + --fetch-limit limit to apply to queries that fetch rows [env: + OMDB_FETCH_LIMIT=] [default: 500] + --include-deleted whether to include soft-deleted records when enumerating objects + that can be soft-deleted + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["mgs"] termination: Exited(2) @@ -293,8 +402,15 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --mgs-url URL of an MGS instance to query [env: OMDB_MGS_URL=] - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --mgs-url URL of an MGS instance to query [env: OMDB_MGS_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["nexus"] termination: Exited(2) @@ -313,9 +429,16 @@ Commands: help Print this message or the help of the given subcommand(s) Options: + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: --nexus-internal-url URL of the Nexus internal API [env: OMDB_NEXUS_URL=] - -h, --help Print help + --dns-server [env: OMDB_DNS_SERVER=] + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["nexus", "background-tasks"] termination: Exited(2) @@ -325,7 +448,7 @@ stdout: stderr: print information about background tasks -Usage: omdb nexus background-tasks +Usage: omdb nexus background-tasks [OPTIONS] Commands: doc Show documentation about background tasks @@ -335,7 +458,16 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --nexus-internal-url URL of the Nexus internal API [env: + OMDB_NEXUS_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["nexus", "blueprints"] termination: Exited(2) @@ -345,7 +477,7 @@ stdout: stderr: interact with blueprints -Usage: omdb nexus blueprints +Usage: omdb nexus blueprints [OPTIONS] Commands: list List all blueprints @@ -358,7 +490,16 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --nexus-internal-url URL of the Nexus internal API [env: + OMDB_NEXUS_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["nexus", "sleds"] termination: Exited(2) @@ -368,7 +509,7 @@ stdout: stderr: interact with sleds -Usage: omdb nexus sleds +Usage: omdb nexus sleds [OPTIONS] Commands: list-uninitialized List all uninitialized sleds @@ -377,7 +518,16 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --nexus-internal-url URL of the Nexus internal API [env: + OMDB_NEXUS_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["sled-agent"] termination: Exited(2) @@ -396,8 +546,15 @@ Commands: help Print this message or the help of the given subcommand(s) Options: + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: --sled-agent-url URL of the Sled internal API [env: OMDB_SLED_AGENT_URL=] - -h, --help Print help + --dns-server [env: OMDB_DNS_SERVER=] + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["sled-agent", "zones"] termination: Exited(2) @@ -407,14 +564,22 @@ stdout: stderr: print information about zones -Usage: omdb sled-agent zones +Usage: omdb sled-agent zones [OPTIONS] Commands: list Print list of all running control plane zones help Print this message or the help of the given subcommand(s) Options: - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --sled-agent-url URL of the Sled internal API [env: OMDB_SLED_AGENT_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands ============================================= EXECUTING COMMAND: omdb ["sled-agent", "zpools"] termination: Exited(2) @@ -424,12 +589,20 @@ stdout: stderr: print information about zpools -Usage: omdb sled-agent zpools +Usage: omdb sled-agent zpools [OPTIONS] Commands: list Print list of all zpools managed by the sled agent help Print this message or the help of the given subcommand(s) Options: - -h, --help Print help + --log-level log level filter [env: LOG_LEVEL=] [default: warn] + -h, --help Print help + +Connection Options: + --sled-agent-url URL of the Sled internal API [env: OMDB_SLED_AGENT_URL=] + --dns-server [env: OMDB_DNS_SERVER=] + +Safety Options: + -w, --destructive Allow potentially-destructive subcommands =============================================