From e3f910b7bb452802feca0cfad9da35cefb0ab4f9 Mon Sep 17 00:00:00 2001 From: David Pacheco Date: Fri, 30 Aug 2024 19:19:11 -0700 Subject: [PATCH] make this an external cmd --- Cargo.lock | 15 +++++++++ Cargo.toml | 2 ++ dev-tools/ls-apis/Cargo.toml | 23 +++++++++++++ .../src/ls_clients.rs => ls-apis/src/main.rs} | 33 ++++++++++++++++--- dev-tools/xtask/src/main.rs | 7 ++-- 5 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 dev-tools/ls-apis/Cargo.toml rename dev-tools/{xtask/src/ls_clients.rs => ls-apis/src/main.rs} (97%) diff --git a/Cargo.lock b/Cargo.lock index a5e67adad2..63cb05a609 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6151,6 +6151,21 @@ dependencies = [ "uuid", ] +[[package]] +name = "omicron-ls-apis" +version = "0.1.0" +dependencies = [ + "anyhow", + "camino", + "cargo_metadata", + "clap", + "omicron-zone-package", + "petgraph", + "serde", + "toml 0.8.19", + "url", +] + [[package]] name = "omicron-nexus" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 7c5d1577ef..b4a67409ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ members = [ "dev-tools/crdb-seed", "dev-tools/db-dev", "dev-tools/downloader", + "dev-tools/ls-apis", "dev-tools/mgs-dev", "dev-tools/omdb", "dev-tools/omicron-dev", @@ -145,6 +146,7 @@ default-members = [ "dev-tools/crdb-seed", "dev-tools/db-dev", "dev-tools/downloader", + "dev-tools/ls-apis", "dev-tools/mgs-dev", "dev-tools/omdb", "dev-tools/omicron-dev", diff --git a/dev-tools/ls-apis/Cargo.toml b/dev-tools/ls-apis/Cargo.toml new file mode 100644 index 0000000000..483b031758 --- /dev/null +++ b/dev-tools/ls-apis/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "omicron-ls-apis" +version = "0.1.0" +edition = "2021" +license = "MPL-2.0" + +[lints] +workspace = true + +[dependencies] +anyhow.workspace = true +camino.workspace = true +cargo_metadata.workspace = true +clap.workspace = true +omicron-zone-package.workspace = true +petgraph.workspace = true +serde.workspace = true +toml.workspace = true +url.workspace = true + +[[bin]] +name = "ls-apis" +path = "src/main.rs" diff --git a/dev-tools/xtask/src/ls_clients.rs b/dev-tools/ls-apis/src/main.rs similarity index 97% rename from dev-tools/xtask/src/ls_clients.rs rename to dev-tools/ls-apis/src/main.rs index dc13e752f1..115d12fed6 100644 --- a/dev-tools/xtask/src/ls_clients.rs +++ b/dev-tools/ls-apis/src/main.rs @@ -2,7 +2,7 @@ // 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/. -//! Subcommand: cargo xtask ls-clients +//! Show information about Progenitor-based APIs use anyhow::{anyhow, ensure, Context, Result}; use camino::Utf8Path; @@ -10,7 +10,7 @@ use camino::Utf8PathBuf; use cargo_metadata::DependencyKind; use cargo_metadata::Metadata; use cargo_metadata::Package; -use clap::Args; +use clap::{Args, Parser, Subcommand}; use petgraph::dot::Dot; use serde::Deserialize; use std::collections::BTreeMap; @@ -18,8 +18,24 @@ use std::collections::BTreeSet; use std::fmt::Display; use url::Url; +#[derive(Parser)] +#[command( + name = "ls-apis", + bin_name = "ls-apis", + about = "Show information about Progenitor-based APIs" +)] +struct LsApis { + #[command(subcommand)] + cmd: Cmds, +} + +#[derive(Subcommand)] +enum Cmds { + Show(ShowArgs), +} + #[derive(Args)] -pub struct LsClientsArgs { +pub struct ShowArgs { #[arg(long)] api_manifest: Option, @@ -33,7 +49,14 @@ pub struct LsClientsArgs { adoc: bool, } -pub fn run_cmd(args: LsClientsArgs) -> Result<()> { +fn main() -> Result<()> { + let args = LsApis::parse(); + match args.cmd { + Cmds::Show(args) => run_show(args), + } +} + +pub fn run_show(args: ShowArgs) -> Result<()> { let manifest_dir = Utf8PathBuf::from( std::env::var("CARGO_MANIFEST_DIR") .context("looking up CARGO_MANIFEST_DIR in environment")?, @@ -452,7 +475,7 @@ fn direct_dependents( // // } // } // -fn print_package(p: &ClientPackage, args: &LsClientsArgs) { +fn print_package(p: &ClientPackage, args: &ShowArgs) { if !args.adoc { println!(" package: {} from {}", p.me.name, p.me.location); for d in &p.rdeps { diff --git a/dev-tools/xtask/src/main.rs b/dev-tools/xtask/src/main.rs index 1499ff2042..2d359202de 100644 --- a/dev-tools/xtask/src/main.rs +++ b/dev-tools/xtask/src/main.rs @@ -20,7 +20,6 @@ mod common; #[cfg_attr(not(target_os = "illumos"), allow(dead_code))] mod external; mod live_tests; -mod ls_clients; mod usdt; #[cfg(target_os = "illumos")] @@ -52,8 +51,8 @@ enum Cmds { /// Utilities for working with CockroachDB databases. DbDev(external::External), - /// List Progenitor-based clients (heuristically) - LsClients(ls_clients::LsClientsArgs), + /// Show information about Progenitor-based APIs + LsApis(external::External), /// Check that all features are flagged correctly CheckFeatures(check_features::Args), @@ -137,7 +136,7 @@ fn main() -> Result<()> { } } Cmds::LiveTests(args) => live_tests::run_cmd(args), - Cmds::LsClients(args) => ls_clients::run_cmd(args), + Cmds::LsApis(external) => external.exec_bin("ls-apis"), Cmds::MgsDev(external) => external.exec_bin("mgs-dev"), Cmds::OmicronDev(external) => external.exec_bin("omicron-dev"), Cmds::Openapi(external) => external.exec_bin("openapi-manager"),