From b4d26dc11c116701c84fa0c124270a75f753454e Mon Sep 17 00:00:00 2001 From: aon <21188659+aon@users.noreply.github.com> Date: Fri, 24 May 2024 16:07:25 -0300 Subject: [PATCH] feat: remove repeated args --- .../commands/database/args/check_sqlx_data.rs | 21 ---------------- .../src/commands/database/args/drop.rs | 21 ---------------- .../src/commands/database/args/migrate.rs | 24 ------------------- .../src/commands/database/args/mod.rs | 6 ----- .../src/commands/database/args/prepare.rs | 21 ---------------- .../src/commands/database/args/reset.rs | 21 ---------------- .../src/commands/database/args/setup.rs | 21 ---------------- .../src/commands/database/check_sqlx_data.rs | 12 +++++----- .../src/commands/database/drop.rs | 12 +++++----- .../src/commands/database/migrate.rs | 12 +++++----- .../src/commands/database/mod.rs | 18 ++++++-------- .../src/commands/database/prepare.rs | 12 +++++----- .../src/commands/database/reset.rs | 12 +++++----- .../src/commands/database/setup.rs | 12 +++++----- 14 files changed, 43 insertions(+), 182 deletions(-) delete mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/database/args/check_sqlx_data.rs delete mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/database/args/drop.rs delete mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/database/args/migrate.rs delete mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/database/args/prepare.rs delete mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/database/args/reset.rs delete mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/database/args/setup.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/check_sqlx_data.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/check_sqlx_data.rs deleted file mode 100644 index 314b398b2dc0..000000000000 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/check_sqlx_data.rs +++ /dev/null @@ -1,21 +0,0 @@ -use super::{DatabaseCommonArgs, DatabaseCommonArgsFinal}; -use clap::Parser; - -#[derive(Debug, Parser)] -pub struct DatabaseCheckSqlxDataArgs { - #[clap(flatten)] - pub common: DatabaseCommonArgs, -} - -impl DatabaseCheckSqlxDataArgs { - pub fn fill_values_with_prompt(self) -> DatabaseCheckSqlxDataArgsFinal { - let common = self.common.fill_values_with_prompt("check sqlx data for"); - - DatabaseCheckSqlxDataArgsFinal { common } - } -} - -#[derive(Debug)] -pub struct DatabaseCheckSqlxDataArgsFinal { - pub common: DatabaseCommonArgsFinal, -} diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/drop.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/drop.rs deleted file mode 100644 index 16f765b613d4..000000000000 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/drop.rs +++ /dev/null @@ -1,21 +0,0 @@ -use super::{DatabaseCommonArgs, DatabaseCommonArgsFinal}; -use clap::Parser; - -#[derive(Debug, Parser)] -pub struct DatabaseDropArgs { - #[clap(flatten)] - pub common: DatabaseCommonArgs, -} - -impl DatabaseDropArgs { - pub fn fill_values_with_prompt(self) -> DatabaseDropArgsFinal { - let common = self.common.fill_values_with_prompt("drop"); - - DatabaseDropArgsFinal { common } - } -} - -#[derive(Debug)] -pub struct DatabaseDropArgsFinal { - pub common: DatabaseCommonArgsFinal, -} diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/migrate.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/migrate.rs deleted file mode 100644 index 3916651f37fa..000000000000 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/migrate.rs +++ /dev/null @@ -1,24 +0,0 @@ -use super::{DatabaseCommonArgs, DatabaseCommonArgsFinal}; -use clap::Parser; - -#[derive(Debug, Parser)] -pub struct DatabaseMigrateArgs { - #[clap(flatten)] - pub common: DatabaseCommonArgs, - /// Skip confirmation - #[clap(short)] - pub yes: bool, -} - -impl DatabaseMigrateArgs { - pub fn fill_values_with_prompt(self) -> DatabaseMigrateArgsFinal { - let common = self.common.fill_values_with_prompt("migrate"); - - DatabaseMigrateArgsFinal { common } - } -} - -#[derive(Debug)] -pub struct DatabaseMigrateArgsFinal { - pub common: DatabaseCommonArgsFinal, -} diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/mod.rs index 4b9d34e7eacc..bf601c84af5d 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/mod.rs @@ -1,12 +1,6 @@ use clap::Parser; -pub mod check_sqlx_data; -pub mod drop; -pub mod migrate; pub mod new_migration; -pub mod prepare; -pub mod reset; -pub mod setup; #[derive(Debug, Parser)] pub struct DatabaseCommonArgs { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/prepare.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/prepare.rs deleted file mode 100644 index 10d23df0bd6c..000000000000 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/prepare.rs +++ /dev/null @@ -1,21 +0,0 @@ -use super::{DatabaseCommonArgs, DatabaseCommonArgsFinal}; -use clap::Parser; - -#[derive(Debug, Parser)] -pub struct DatabasePrepareArgs { - #[clap(flatten)] - pub common: DatabaseCommonArgs, -} - -impl DatabasePrepareArgs { - pub fn fill_values_with_prompt(self) -> DatabasePrepareArgsFinal { - let common = self.common.fill_values_with_prompt("prepare"); - - DatabasePrepareArgsFinal { common } - } -} - -#[derive(Debug)] -pub struct DatabasePrepareArgsFinal { - pub common: DatabaseCommonArgsFinal, -} diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/reset.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/reset.rs deleted file mode 100644 index b96360229efb..000000000000 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/reset.rs +++ /dev/null @@ -1,21 +0,0 @@ -use super::{DatabaseCommonArgs, DatabaseCommonArgsFinal}; -use clap::Parser; - -#[derive(Debug, Parser)] -pub struct DatabaseResetArgs { - #[clap(flatten)] - pub common: DatabaseCommonArgs, -} - -impl DatabaseResetArgs { - pub fn fill_values_with_prompt(self) -> DatabaseResetArgsFinal { - let common = self.common.fill_values_with_prompt("reset"); - - DatabaseResetArgsFinal { common } - } -} - -#[derive(Debug)] -pub struct DatabaseResetArgsFinal { - pub common: DatabaseCommonArgsFinal, -} diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/setup.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/setup.rs deleted file mode 100644 index 7c251bb63ca2..000000000000 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/setup.rs +++ /dev/null @@ -1,21 +0,0 @@ -use super::{DatabaseCommonArgs, DatabaseCommonArgsFinal}; -use clap::Parser; - -#[derive(Debug, Parser)] -pub struct DatabaseSetupArgs { - #[clap(flatten)] - pub common: DatabaseCommonArgs, -} - -impl DatabaseSetupArgs { - pub fn fill_values_with_prompt(self) -> DatabaseSetupArgsFinal { - let common = self.common.fill_values_with_prompt("setup"); - - DatabaseSetupArgsFinal { common } - } -} - -#[derive(Debug)] -pub struct DatabaseSetupArgsFinal { - pub common: DatabaseCommonArgsFinal, -} diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/check_sqlx_data.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/check_sqlx_data.rs index d79a3607802e..73d7897279ac 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/check_sqlx_data.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/check_sqlx_data.rs @@ -1,13 +1,13 @@ -use super::args::check_sqlx_data::DatabaseCheckSqlxDataArgs; +use super::args::DatabaseCommonArgs; use crate::dals::{get_core_dal, get_prover_dal, Dal}; use common::{cmd::Cmd, logger, spinner::Spinner}; use std::path::Path; use xshell::{cmd, Shell}; use zk_inception::configs::EcosystemConfig; -pub fn run(shell: &Shell, args: DatabaseCheckSqlxDataArgs) -> anyhow::Result<()> { - let args = args.fill_values_with_prompt(); - if !args.common.prover && !args.common.core { +pub fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt("check sqlx data for"); + if !args.prover && !args.core { logger::outro("No databases selected to check"); return Ok(()); } @@ -16,14 +16,14 @@ pub fn run(shell: &Shell, args: DatabaseCheckSqlxDataArgs) -> anyhow::Result<()> logger::info("Checking sqlx data"); - if args.common.prover { + if args.prover { check_sqlx_data( shell, &ecosystem_config.link_to_code, get_prover_dal(shell)?, )?; } - if args.common.core { + if args.core { check_sqlx_data(shell, &ecosystem_config.link_to_code, get_core_dal(shell)?)?; } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs index 5de56f650904..1e59996a77f1 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs @@ -1,4 +1,4 @@ -use super::args::drop::DatabaseDropArgs; +use super::args::DatabaseCommonArgs; use crate::dals::{get_core_dal, get_prover_dal, Dal}; use common::{ db::{drop_db_if_exists, split_db_url}, @@ -7,19 +7,19 @@ use common::{ }; use xshell::Shell; -pub async fn run(shell: &Shell, args: DatabaseDropArgs) -> anyhow::Result<()> { - let args = args.fill_values_with_prompt(); - if !args.common.prover && !args.common.core { +pub async fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt("drop"); + if !args.prover && !args.core { logger::outro("No databases selected to drop"); return Ok(()); } logger::info("Dropping databases"); - if args.common.prover { + if args.prover { drop_database(get_prover_dal(shell)?).await?; } - if args.common.core { + if args.core { drop_database(get_core_dal(shell)?).await?; } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/migrate.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/migrate.rs index c1537f643c2a..d1a129f0226b 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/migrate.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/migrate.rs @@ -1,13 +1,13 @@ -use super::args::migrate::DatabaseMigrateArgs; +use super::args::DatabaseCommonArgs; use crate::dals::{get_core_dal, get_prover_dal, Dal}; use common::{cmd::Cmd, logger, spinner::Spinner}; use std::path::Path; use xshell::{cmd, Shell}; use zk_inception::configs::EcosystemConfig; -pub fn run(shell: &Shell, args: DatabaseMigrateArgs) -> anyhow::Result<()> { - let args = args.fill_values_with_prompt(); - if !args.common.prover && !args.common.core { +pub fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt("migrate"); + if !args.prover && !args.core { logger::outro("No databases selected to migrate"); return Ok(()); } @@ -15,10 +15,10 @@ pub fn run(shell: &Shell, args: DatabaseMigrateArgs) -> anyhow::Result<()> { logger::info("Migrating databases"); let ecosystem_config = EcosystemConfig::from_file(shell)?; - if args.common.core { + if args.core { migrate_database(shell, &ecosystem_config.link_to_code, get_core_dal(shell)?)?; } - if args.common.prover { + if args.prover { migrate_database( shell, &ecosystem_config.link_to_code, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs index 05147dcdcacb..cbfda3d70359 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs @@ -1,8 +1,4 @@ -use self::args::{ - check_sqlx_data::DatabaseCheckSqlxDataArgs, drop::DatabaseDropArgs, - migrate::DatabaseMigrateArgs, new_migration::DatabaseNewMigrationArgs, - prepare::DatabasePrepareArgs, reset::DatabaseResetArgs, setup::DatabaseSetupArgs, -}; +use self::args::{new_migration::DatabaseNewMigrationArgs, DatabaseCommonArgs}; use clap::Subcommand; use xshell::Shell; @@ -18,19 +14,19 @@ mod setup; #[derive(Subcommand, Debug)] pub enum DatabaseCommands { /// Check sqlx-data.json is up to date - CheckSqlxData(DatabaseCheckSqlxDataArgs), + CheckSqlxData(DatabaseCommonArgs), /// Drop databases - Drop(DatabaseDropArgs), + Drop(DatabaseCommonArgs), /// Migrate databases - Migrate(DatabaseMigrateArgs), + Migrate(DatabaseCommonArgs), /// Create new migration NewMigration(DatabaseNewMigrationArgs), /// Prepare sqlx-data.json - Prepare(DatabasePrepareArgs), + Prepare(DatabaseCommonArgs), /// Reset databases - Reset(DatabaseResetArgs), + Reset(DatabaseCommonArgs), /// Setup databases - Setup(DatabaseSetupArgs), + Setup(DatabaseCommonArgs), } pub async fn run(shell: &Shell, args: DatabaseCommands) -> anyhow::Result<()> { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/prepare.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/prepare.rs index cf7d82524330..28feecdbce7b 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/prepare.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/prepare.rs @@ -1,13 +1,13 @@ -use super::args::prepare::DatabasePrepareArgs; +use super::args::DatabaseCommonArgs; use crate::dals::{get_core_dal, get_prover_dal, Dal}; use common::{cmd::Cmd, logger, spinner::Spinner}; use std::path::Path; use xshell::{cmd, Shell}; use zk_inception::configs::EcosystemConfig; -pub fn run(shell: &Shell, args: DatabasePrepareArgs) -> anyhow::Result<()> { - let args = args.fill_values_with_prompt(); - if !args.common.prover && !args.common.core { +pub fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt("prepare"); + if !args.prover && !args.core { logger::outro("No databases selected to prepare"); return Ok(()); } @@ -16,14 +16,14 @@ pub fn run(shell: &Shell, args: DatabasePrepareArgs) -> anyhow::Result<()> { logger::info("Preparing sqlx data"); - if args.common.prover { + if args.prover { prepare_sqlx_data( shell, &ecosystem_config.link_to_code, get_prover_dal(shell)?, )?; } - if args.common.core { + if args.core { prepare_sqlx_data(shell, &ecosystem_config.link_to_code, get_core_dal(shell)?)?; } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs index 2d177144056f..16c287df0b97 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs @@ -1,20 +1,20 @@ -use super::{args::reset::DatabaseResetArgs, drop::drop_database, setup::setup_database}; +use super::{args::DatabaseCommonArgs, drop::drop_database, setup::setup_database}; use crate::dals::{get_core_dal, get_prover_dal, Dal}; use common::logger; use std::path::Path; use xshell::Shell; use zk_inception::configs::EcosystemConfig; -pub async fn run(shell: &Shell, args: DatabaseResetArgs) -> anyhow::Result<()> { - let args = args.fill_values_with_prompt(); - if !args.common.prover && !args.common.core { +pub async fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt("reset"); + if !args.prover && !args.core { logger::outro("No databases selected"); return Ok(()); } let ecoseystem_config = EcosystemConfig::from_file(shell)?; - if args.common.prover { + if args.prover { logger::info("Resetting prover database"); reset_database( shell, @@ -23,7 +23,7 @@ pub async fn run(shell: &Shell, args: DatabaseResetArgs) -> anyhow::Result<()> { ) .await?; } - if args.common.core { + if args.core { logger::info("Resetting core database"); reset_database(shell, ecoseystem_config.link_to_code, get_core_dal(shell)?).await?; } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/setup.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/setup.rs index 48175a8d112c..8cefee9f1693 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/setup.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/setup.rs @@ -1,13 +1,13 @@ -use super::args::setup::DatabaseSetupArgs; +use super::args::DatabaseCommonArgs; use crate::dals::{get_core_dal, get_prover_dal, Dal}; use common::{cmd::Cmd, logger, spinner::Spinner}; use std::path::Path; use xshell::{cmd, Shell}; use zk_inception::configs::EcosystemConfig; -pub fn run(shell: &Shell, args: DatabaseSetupArgs) -> anyhow::Result<()> { - let args = args.fill_values_with_prompt(); - if !args.common.prover && !args.common.core { +pub fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt("setup"); + if !args.prover && !args.core { logger::outro("No databases selected to setup"); return Ok(()); } @@ -16,14 +16,14 @@ pub fn run(shell: &Shell, args: DatabaseSetupArgs) -> anyhow::Result<()> { logger::info("Setting up databases"); - if args.common.prover { + if args.prover { setup_database( shell, &ecosystem_config.link_to_code, get_prover_dal(shell)?, )?; } - if args.common.core { + if args.core { setup_database(shell, &ecosystem_config.link_to_code, get_core_dal(shell)?)?; }