Skip to content

Commit

Permalink
Additional refactor to reduce cycles even more.
Browse files Browse the repository at this point in the history
  • Loading branch information
DFINITYManu committed Feb 20, 2025
1 parent d56a6d5 commit c85a83b
Show file tree
Hide file tree
Showing 59 changed files with 300 additions and 260 deletions.
5 changes: 3 additions & 2 deletions rs/cli/src/commands/api_boundary_nodes/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use ic_types::PrincipalId;

use crate::{
auth::AuthRequirement,
ctx::exe::ExecutableCommand,
exe::args::GlobalArgs,
exe::ExecutableCommand,
forum::ForumPostKind,
ic_admin::{self},
submitter::{SubmissionParameters, Submitter},
Expand Down Expand Up @@ -51,5 +52,5 @@ impl ExecutableCommand for Add {
.await
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/api_boundary_nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::Args;
use remove::Remove;
use update::Update;

use crate::ctx::exe::impl_executable_command_for_enums;
use crate::exe::impl_executable_command_for_enums;

mod add;
mod remove;
Expand Down
5 changes: 3 additions & 2 deletions rs/cli/src/commands/api_boundary_nodes/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use ic_types::PrincipalId;

use crate::{
auth::AuthRequirement,
ctx::exe::ExecutableCommand,
exe::args::GlobalArgs,
exe::ExecutableCommand,
forum::ForumPostKind,
ic_admin::{self},
submitter::{SubmissionParameters, Submitter},
Expand Down Expand Up @@ -44,5 +45,5 @@ impl ExecutableCommand for Remove {
.await
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {}
}
5 changes: 3 additions & 2 deletions rs/cli/src/commands/api_boundary_nodes/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use ic_types::PrincipalId;

use crate::{
auth::AuthRequirement,
ctx::exe::ExecutableCommand,
exe::args::GlobalArgs,
exe::ExecutableCommand,
forum::ForumPostKind,
ic_admin::{self},
submitter::{SubmissionParameters, Submitter},
Expand Down Expand Up @@ -50,5 +51,5 @@ impl ExecutableCommand for Update {
.await
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {}
}
26 changes: 0 additions & 26 deletions rs/cli/src/commands/completions.rs

This file was deleted.

5 changes: 3 additions & 2 deletions rs/cli/src/commands/der_to_principal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::path::PathBuf;

use clap::Args;

use super::{AuthRequirement, ExecutableCommand};
use crate::auth::AuthRequirement;
use crate::exe::{ExecutableCommand, args::GlobalArgs};

#[derive(Args, Debug)]
pub struct DerToPrincipal {
Expand All @@ -21,5 +22,5 @@ impl ExecutableCommand for DerToPrincipal {
Ok(())
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {}
}
8 changes: 4 additions & 4 deletions rs/cli/src/commands/firewall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use serde::{Deserialize, Serialize};
use tempfile::NamedTempFile;

use crate::{
auth::AuthRequirement,
ctx::DreContext,
exe::{ExecutableCommand, args::GlobalArgs},
forum::ForumPostKind,
ic_admin::{IcAdminProposal, IcAdminProposalCommand, IcAdminProposalOptions},
proposal_executors::{ProducesProposalResult, ProposalResponseWithId, RunnableViaIcAdmin},
submitter::{SubmissionParameters, Submitter},
};

use super::{AuthRequirement, ExecutableCommand};

#[derive(Args, Debug)]
pub struct Firewall {
#[clap(long, default_value = Some("Proposal to modify firewall rules"))]
Expand All @@ -43,7 +43,7 @@ impl ExecutableCommand for Firewall {
AuthRequirement::Neuron
}

async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
async fn execute(&self, ctx: DreContext) -> anyhow::Result<()> {
let registry = ctx.registry().await;
let firewall_ruleset = registry.firewall_rule_set(self.rules_scope.clone()).await?;

Expand Down Expand Up @@ -120,7 +120,7 @@ impl ExecutableCommand for Firewall {
}
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {}
}

#[derive(Deserialize)]
Expand Down
5 changes: 3 additions & 2 deletions rs/cli/src/commands/get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Args;

use super::{AuthRequirement, ExecutableCommand};
use crate::auth::AuthRequirement;
use crate::exe::{args::GlobalArgs, ExecutableCommand};

#[derive(Args, Debug)]
pub struct Get {
Expand All @@ -18,5 +19,5 @@ impl ExecutableCommand for Get {
ctx.get(&self.args).await
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {}
}
4 changes: 3 additions & 1 deletion rs/cli/src/commands/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ mod propose;

use propose::Propose;

use crate::exe::impl_executable_command_for_enums;

#[derive(Args, Debug)]
/// Commands and actions related to governance.
pub struct Governance {
#[clap(subcommand)]
pub subcommands: Subcommands,
}

super::impl_executable_command_for_enums! { Governance, Propose }
impl_executable_command_for_enums! { Governance, Propose }
4 changes: 2 additions & 2 deletions rs/cli/src/commands/governance/propose/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use clap::Args;
mod motion;

use crate::commands::impl_executable_command_for_enums;

use motion::Motion;

use crate::exe::impl_executable_command_for_enums;

#[derive(Args, Debug)]
/// Creation of proposals.
pub struct Propose {
Expand Down
7 changes: 5 additions & 2 deletions rs/cli/src/commands/governance/propose/motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use tokio::io::AsyncReadExt;

use crate::{
auth::AuthRequirement,
ctx::exe::ExecutableCommand,
exe::args::GlobalArgs,
exe::ExecutableCommand,
forum::ForumPostKind,
submitter::{SubmissionParameters, Submitter},
util::{extract_title_and_text, utf8},
Expand Down Expand Up @@ -90,5 +91,7 @@ impl ExecutableCommand for Motion {
.await
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {
let _ = _args;
}
}
4 changes: 3 additions & 1 deletion rs/cli/src/commands/hostos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use clap::Args;
use rollout::Rollout;
use rollout_from_node_group::RolloutFromNodeGroup;

use crate::exe::impl_executable_command_for_enums;

mod rollout;
pub mod rollout_from_node_group;

Expand All @@ -11,4 +13,4 @@ pub struct HostOs {
pub subcommands: Subcommands,
}

super::impl_executable_command_for_enums! { HostOs, Rollout, RolloutFromNodeGroup }
impl_executable_command_for_enums! { HostOs, Rollout, RolloutFromNodeGroup }
5 changes: 3 additions & 2 deletions rs/cli/src/commands/hostos/rollout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use ic_types::PrincipalId;

use crate::{
auth::AuthRequirement,
ctx::exe::ExecutableCommand,
exe::args::GlobalArgs,
exe::ExecutableCommand,
forum::ForumPostKind,
submitter::{SubmissionParameters, Submitter},
};
Expand Down Expand Up @@ -34,5 +35,5 @@ impl ExecutableCommand for Rollout {
.await
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {}
}
5 changes: 3 additions & 2 deletions rs/cli/src/commands/hostos/rollout_from_node_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use clap::{Args, ValueEnum};

use crate::{
auth::AuthRequirement,
ctx::exe::ExecutableCommand,
exe::args::GlobalArgs,
exe::ExecutableCommand,
forum::ForumPostKind,
operations::hostos_rollout::{NodeGroupUpdate, NumberOfNodes},
submitter::{SubmissionParameters, Submitter},
Expand Down Expand Up @@ -104,5 +105,5 @@ impl ExecutableCommand for RolloutFromNodeGroup {
.await
}

fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {}
}
58 changes: 58 additions & 0 deletions rs/cli/src/commands/main_command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use super::api_boundary_nodes::ApiBoundaryNodes;
use super::der_to_principal::DerToPrincipal;
use super::firewall::Firewall;
use super::get::Get;
use super::governance::Governance;
use super::hostos::HostOs;
use super::network::Network;
use super::neuron::Neuron;
use super::node_metrics::NodeMetrics;
use super::nodes::Nodes;
use super::proposals::Proposals;
use super::propose::Propose;
use super::qualify::Qualify;
use super::registry::Registry;
use super::update_authorized_subnets::UpdateAuthorizedSubnets;
use super::update_unassigned_nodes::UpdateUnassignedNodes;
use super::upgrade::Upgrade;
use super::version::Version;
use super::vote::Vote;
use crate::commands::subnet::Subnet;
use crate::exe::impl_executable_command_for_enums;
use clap::Parser;
use clap::{Args, CommandFactory};
use clap_complete::{generate, Shell};

#[derive(Parser, Debug)]
#[clap(version = env!("CARGO_PKG_VERSION"), about, author)]
pub struct MainCommand {
#[clap(flatten)]
pub global_args: GlobalArgs,

#[clap(subcommand)]
pub subcommands: Subcommands,
}

impl_executable_command_for_enums! { MainCommand, DerToPrincipal, Network, Subnet, Get, Propose, UpdateUnassignedNodes, Version, NodeMetrics, HostOs, Nodes, ApiBoundaryNodes, Vote, Registry, Firewall, Upgrade, Proposals, Completions, Qualify, UpdateAuthorizedSubnets, Neuron, Governance }

#[derive(Args, Debug)]
pub struct Completions {
#[clap(long, short, default_value_t = Shell::Bash)]
shell: Shell,
}

impl ExecutableCommand for Completions {
fn require_auth(&self) -> AuthRequirement {
AuthRequirement::Anonymous
}

fn validate(&self, _args: &GlobalArgs, _cmd: &mut clap::Command) {}

async fn execute(&self, _ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let mut command = MainCommand::command();

generate(self.shell, &mut command, "dre", &mut std::io::stdout());

Ok(())
}
}
Loading

0 comments on commit c85a83b

Please sign in to comment.