Skip to content

Commit

Permalink
feat(dre): Add support for forum post links for version elect proposa…
Browse files Browse the repository at this point in the history
…ls (#942)
  • Loading branch information
sasa-tomic authored Sep 26, 2024
1 parent 480ac78 commit fb3e145
Show file tree
Hide file tree
Showing 48 changed files with 93 additions and 71 deletions.
2 changes: 1 addition & 1 deletion rs/cli/src/commands/api_boundary_nodes/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ impl ExecutableCommand for Add {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
4 changes: 2 additions & 2 deletions rs/cli/src/commands/api_boundary_nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl ExecutableCommand for ApiBoundaryNodes {
self.subcommand.execute(ctx).await
}

fn validate(&self, cmd: &mut clap::Command) {
self.subcommand.validate(cmd)
fn validate(&self, args: &crate::commands::Args, cmd: &mut clap::Command) {
self.subcommand.validate(args, cmd)
}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/api_boundary_nodes/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ impl ExecutableCommand for Remove {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/api_boundary_nodes/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ impl ExecutableCommand for Update {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl ExecutableCommand for Completions {
super::AuthRequirement::Anonymous
}

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

async fn execute(&self, _ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let mut command = super::Args::command();
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/der_to_principal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ impl ExecutableCommand for DerToPrincipal {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/firewall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl ExecutableCommand for Firewall {
}
}

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

impl Firewall {
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ impl ExecutableCommand for Get {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/heal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ impl ExecutableCommand for Heal {
runner.network_heal(ctx.forum_post_link()).await
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
4 changes: 2 additions & 2 deletions rs/cli/src/commands/hostos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl ExecutableCommand for HostOs {
self.subcommand.execute(ctx).await
}

fn validate(&self, cmd: &mut clap::Command) {
self.subcommand.validate(cmd)
fn validate(&self, args: &crate::commands::Args, cmd: &mut clap::Command) {
self.subcommand.validate(args, cmd)
}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/hostos/rollout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ impl ExecutableCommand for Rollout {
.await
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/hostos/rollout_from_node_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ impl ExecutableCommand for RolloutFromNodeGroup {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
18 changes: 12 additions & 6 deletions rs/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl TryFrom<PathBuf> for AuthOpts {

#[derive(Parser, Debug)]
#[clap(version = env!("CARGO_PKG_VERSION"), about, author)]
pub(crate) struct Args {
pub struct Args {
#[clap(flatten)]
pub(crate) auth_opts: AuthOpts,

Expand Down Expand Up @@ -214,8 +214,14 @@ impl ExecutableCommand for Args {
self.subcommands.execute(ctx).await
}

fn validate(&self, cmd: &mut Command) {
self.subcommands.validate(cmd)
/// Validate the command line arguments. You can return an error with something like:
/// ```rust
/// if args.neuron_id.is_none() {
/// cmd.error(ErrorKind::MissingRequiredArgument, "Neuron ID is required for this command.")).exit();
/// }
/// ```
fn validate(&self, args: &crate::commands::Args, cmd: &mut Command) {
self.subcommands.validate(args, cmd)
}
}

Expand All @@ -242,9 +248,9 @@ macro_rules! impl_executable_command_for_enums {
}
}

fn validate(&self, cmd: &mut Command) {
fn validate(&self, args: &crate::commands::Args, cmd: &mut Command) {
match &self {
$(Subcommands::$var(variant) => variant.validate(cmd),)*
$(Subcommands::$var(variant) => variant.validate(args, cmd),)*
}
}
}
Expand All @@ -257,7 +263,7 @@ impl_executable_command_for_enums! { DerToPrincipal, Heal, Subnet, Get, Propose,
pub trait ExecutableCommand {
fn require_auth(&self) -> AuthRequirement;

fn validate(&self, cmd: &mut Command);
fn validate(&self, args: &crate::commands::Args, cmd: &mut Command);

fn execute(&self, ctx: DreContext) -> impl std::future::Future<Output = anyhow::Result<()>>;
}
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/neuron/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl ExecutableCommand for Balance {
}
}

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

async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let governance = GovernanceCanisterWrapper::from(ctx.create_ic_agent_canister_client(None)?);
Expand Down
4 changes: 2 additions & 2 deletions rs/cli/src/commands/neuron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl ExecutableCommand for Neuron {
self.subcommand.require_auth()
}

fn validate(&self, cmd: &mut Command) {
self.subcommand.validate(cmd)
fn validate(&self, args: &crate::commands::Args, cmd: &mut Command) {
self.subcommand.validate(args, cmd)
}

async fn execute(&self, ctx: DreContext) -> anyhow::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/neuron/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl ExecutableCommand for Refresh {
crate::commands::AuthRequirement::Neuron
}

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

async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let governance_canister = GovernanceCanisterWrapper::from(ctx.create_ic_agent_canister_client(None)?);
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/neuron/top_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl ExecutableCommand for TopUp {
crate::commands::AuthRequirement::Neuron
}

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

async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let governance = GovernanceCanisterWrapper::from(ctx.create_ic_agent_canister_client(None)?);
Expand Down
3 changes: 1 addition & 2 deletions rs/cli/src/commands/node_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
sync::{Arc, Mutex},
};

use anyhow::Ok;
use clap::{error::ErrorKind, Args};
use ic_canisters::{
management::{NodeMetricsHistoryResponse, WalletCanisterWrapper},
Expand Down Expand Up @@ -145,7 +144,7 @@ impl ExecutableCommand for NodeMetrics {
Ok(())
}

fn validate(&self, cmd: &mut clap::Command) {
fn validate(&self, _args: &crate::commands::Args, cmd: &mut clap::Command) {
if self.trustworthy && self.wallet.is_none() {
cmd.error(ErrorKind::MissingRequiredArgument, "Wallet is required for fetching trustworthy metrics.")
.exit();
Expand Down
4 changes: 2 additions & 2 deletions rs/cli/src/commands/nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl ExecutableCommand for Nodes {
self.subcommand.execute(ctx).await
}

fn validate(&self, cmd: &mut clap::Command) {
self.subcommand.validate(cmd)
fn validate(&self, args: &crate::commands::Args, cmd: &mut clap::Command) {
self.subcommand.validate(args, cmd)
}
}
4 changes: 2 additions & 2 deletions rs/cli/src/commands/nodes/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ impl ExecutableCommand for Remove {
.await
}

fn validate(&self, cmd: &mut clap::Command) {
fn validate(&self, _args: &crate::commands::Args, cmd: &mut clap::Command) {
if self.motivation.is_none() && !self.extra_nodes_filter.is_empty() {
cmd.error(ErrorKind::MissingRequiredArgument, "Required argument motivation not found")
.exit();
.exit()
}
}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/proposals/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ impl ExecutableCommand for Analyze {
}
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/proposals/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,5 @@ impl ExecutableCommand for Filter {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/proposals/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ impl ExecutableCommand for Get {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/proposals/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ impl ExecutableCommand for List {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
4 changes: 2 additions & 2 deletions rs/cli/src/commands/proposals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ impl ExecutableCommand for Proposals {
self.subcommand.execute(ctx).await
}

fn validate(&self, cmd: &mut clap::Command) {
self.subcommand.validate(cmd)
fn validate(&self, args: &crate::commands::Args, cmd: &mut clap::Command) {
self.subcommand.validate(args, cmd)
}
}

Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/proposals/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ impl ExecutableCommand for Pending {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/propose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ impl ExecutableCommand for Propose {
Ok(())
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/qualify/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ExecutableCommand for Execute {
crate::commands::AuthRequirement::Neuron
}

fn validate(&self, cmd: &mut clap::Command) {
fn validate(&self, _args: &crate::commands::Args, cmd: &mut clap::Command) {
if self.artifacts.is_some() && self.grafana_url.is_none() {
cmd.error(
clap::error::ErrorKind::InvalidValue,
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/qualify/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl ExecutableCommand for List {
crate::commands::AuthRequirement::Anonymous
}

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

async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let qualification_executor = QualificationExecutorBuilder::new(ctx)
Expand Down
4 changes: 2 additions & 2 deletions rs/cli/src/commands/qualify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ impl ExecutableCommand for Qualify {
self.subcommand.require_auth()
}

fn validate(&self, cmd: &mut clap::Command) {
self.subcommand.validate(cmd)
fn validate(&self, args: &crate::commands::Args, cmd: &mut clap::Command) {
self.subcommand.validate(args, cmd)
}

async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl ExecutableCommand for Registry {
Ok(())
}

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

impl Registry {
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/subnet/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl ExecutableCommand for Create {
.await
}

fn validate(&self, cmd: &mut clap::Command) {
fn validate(&self, _args: &crate::commands::Args, cmd: &mut clap::Command) {
if self.motivation.is_none() && !self.help_other_args {
cmd.error(
ErrorKind::MissingRequiredArgument,
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/commands/subnet/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ impl ExecutableCommand for Deploy {
runner.deploy(&self.id, &self.version, ctx.forum_post_link()).await
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
4 changes: 2 additions & 2 deletions rs/cli/src/commands/subnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl ExecutableCommand for Subnet {
self.subcommand.execute(ctx).await
}

fn validate(&self, cmd: &mut clap::Command) {
self.subcommand.validate(cmd)
fn validate(&self, args: &crate::commands::Args, cmd: &mut clap::Command) {
self.subcommand.validate(args, cmd)
}
}
8 changes: 4 additions & 4 deletions rs/cli/src/commands/subnet/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ impl ExecutableCommand for Replace {
runner.propose_subnet_change(subnet_change_response, ctx.forum_post_link()).await
}

fn validate(&self, cmd: &mut clap::Command) {
fn validate(&self, _args: &crate::commands::Args, cmd: &mut clap::Command) {
if !self.nodes.is_empty() && self.id.is_some() {
cmd.error(
ErrorKind::ArgumentConflict,
"Both subnet id and a list of nodes to replace are provided. Only one of the two is allowed.",
)
.exit();
.exit()
} else if self.nodes.is_empty() && self.id.is_none() {
cmd.error(
ErrorKind::MissingRequiredArgument,
"Specify either a subnet id or a list of nodes to replace",
)
.exit();
.exit()
} else if !self.nodes.is_empty() && self.motivation.is_none() {
cmd.error(ErrorKind::MissingRequiredArgument, "Required argument motivation not found")
.exit();
.exit()
}
}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/subnet/rescue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ impl ExecutableCommand for Rescue {
runner.subnet_rescue(&self.id, self.keep_nodes.clone(), ctx.forum_post_link()).await
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/subnet/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ impl ExecutableCommand for Resize {
runner.propose_subnet_change(subnet_change_response, ctx.forum_post_link()).await
}

fn validate(&self, _cmd: &mut clap::Command) {}
fn validate(&self, _args: &crate::commands::Args, _cmd: &mut clap::Command) {}
}
2 changes: 1 addition & 1 deletion rs/cli/src/commands/subnet/whatif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ impl ExecutableCommand for WhatifDecentralization {
.await
}

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

0 comments on commit fb3e145

Please sign in to comment.