Skip to content

Commit fa33ab2

Browse files
authored
feat(cli): wcn_operator rename (#316)
1 parent 0419592 commit fa33ab2

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
260113.0
1+
260120.0

crates/operator_cli/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod client;
1010
mod key;
1111
mod maintenance;
1212
mod node;
13+
mod rename;
1314
mod test_client;
1415
mod test_server;
1516
mod view;
@@ -29,6 +30,9 @@ enum Command {
2930
/// Get overview of your Node Operator
3031
View(ClusterArgs),
3132

33+
/// Change the name of your Node Operator
34+
Rename(rename::Args),
35+
3236
/// Key management
3337
#[command(subcommand)]
3438
Key(key::Command),
@@ -103,6 +107,7 @@ async fn main() -> anyhow::Result<()> {
103107

104108
match cli.command {
105109
Command::View(args) => view::execute(args).await?,
110+
Command::Rename(args) => rename::execute(args).await?,
106111
Command::Key(cmd) => key::execute(cmd),
107112
Command::Node(cmd) => node::execute(cmd).await?,
108113
Command::Client(cmd) => client::execute(cmd).await?,

crates/operator_cli/src/rename.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use {crate::ClusterArgs, anyhow::Context, wcn_cluster::node_operator};
2+
3+
#[derive(Debug, clap::Args)]
4+
pub(super) struct Args {
5+
#[command(flatten)]
6+
cluster_args: ClusterArgs,
7+
8+
/// New name
9+
#[arg(long, short)]
10+
name: node_operator::Name,
11+
12+
/// Skip interactive approval of the changes before writing to the
13+
/// Smart-Contract.
14+
#[arg(long)]
15+
auto_approve: bool,
16+
}
17+
18+
pub(super) async fn execute(args: Args) -> anyhow::Result<()> {
19+
let cluster = args.cluster_args.connect().await?;
20+
let mut operator = crate::current_operator(&cluster)?;
21+
22+
println!("Current name: {}", operator.name);
23+
println!("New name: {}", args.name);
24+
25+
operator.name = args.name;
26+
27+
if args.auto_approve || crate::ask_approval()? {
28+
cluster
29+
.update_node_operator(operator)
30+
.await
31+
.context("Cluster::update_node_operator")?;
32+
}
33+
34+
Ok(())
35+
}

0 commit comments

Comments
 (0)