Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[omdb] improve CLI UX #5627

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion dev-tools/omdb/src/bin/omdb/crucible_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

#[command(subcommand)]
Expand Down
22 changes: 18 additions & 4 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PostgresConfigWithUrl>,
}

Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down
9 changes: 9 additions & 0 deletions dev-tools/omdb/src/bin/omdb/helpers.rs
Original file line number Diff line number Diff line change
@@ -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";
16 changes: 14 additions & 2 deletions dev-tools/omdb/src/bin/omdb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use std::net::SocketAddrV6;

mod crucible_agent;
mod db;
mod helpers;
mod mgs;
mod nexus;
mod oximeter;
Expand Down Expand Up @@ -80,14 +81,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<SocketAddr>,

/// Allow potentially-destructive subcommands.
#[arg(short = 'w', long = "destructive", global = true)]
#[arg(
short = 'w',
long = "destructive",
global = true,
help_heading = helpers::SAFETY_OPTIONS_HEADING,
)]
allow_destructive: bool,

#[command(subcommand)]
Expand Down
8 changes: 7 additions & 1 deletion dev-tools/omdb/src/bin/omdb/mgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>,

#[command(subcommand)]
Expand Down
8 changes: 7 additions & 1 deletion dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>,

#[command(subcommand)]
Expand Down
10 changes: 9 additions & 1 deletion dev-tools/omdb/src/bin/omdb/oximeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! omdb commands that query oximeter

use crate::helpers::CONNECTION_OPTIONS_HEADING;
use anyhow::Context;
use clap::Args;
use clap::Subcommand;
Expand All @@ -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)]
Expand Down
8 changes: 7 additions & 1 deletion dev-tools/omdb/src/bin/omdb/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String>,

#[command(subcommand)]
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.