Skip to content

Commit

Permalink
[feature] hyperledger-iroha#3974: Add subcommands into iroha_client_c…
Browse files Browse the repository at this point in the history
…li to edit domain metadata (hyperledger-iroha#4175)

Signed-off-by: Vladimir Pesterev <8786922+pesterev@users.noreply.github.com>
Signed-off-by: VAmuzing <amuzik95@gmail.com>
Co-authored-by: Vladimir Pesterev <8786922+pesterev@users.noreply.github.com>
  • Loading branch information
VAmuzing and pesterev authored Jan 15, 2024
1 parent 5d4082f commit 66072b4
Showing 1 changed file with 73 additions and 2 deletions.
75 changes: 73 additions & 2 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl FromStr for ValueArg {
.or_else(|_| s.parse::<Ipv6Addr>().map(Value::Ipv6Addr))
.or_else(|_| s.parse::<NumericValue>().map(Value::Numeric))
.or_else(|_| s.parse::<PublicKey>().map(Value::PublicKey))
.or_else(|_| serde_json::from_str::<Value>(s).map_err(|e| e.into()))
.or_else(|_| serde_json::from_str::<Value>(s).map_err(std::convert::Into::into))
.map(ValueArg)
}
}
Expand Down Expand Up @@ -393,11 +393,14 @@ mod domain {
List(List),
/// Transfer domain
Transfer(Transfer),
/// Edit domain metadata
#[clap(subcommand)]
Metadata(metadata::Args),
}

impl RunArgs for Args {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
match_all!((self, context), { Args::Register, Args::List, Args::Transfer })
match_all!((self, context), { Args::Register, Args::List, Args::Transfer, Args::Metadata, })
}
}

Expand Down Expand Up @@ -476,6 +479,74 @@ mod domain {
.wrap_err("Failed to transfer domain")
}
}

mod metadata {
use iroha_client::data_model::domain::DomainId;

use super::*;

/// Edit domain subcommands
#[derive(Debug, Clone, clap::Subcommand)]
pub enum Args {
/// Set domain metadata
Set(Set),
/// Remove domain metadata
Remove(Remove),
}

impl RunArgs for Args {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
match_all!((self, context), { Args::Set, Args::Remove, })
}
}

/// Set metadata into domain
#[derive(Debug, Clone, clap::Args)]
pub struct Set {
/// A domain id from which metadata is to be removed
#[arg(short, long)]
id: DomainId,
/// A key of metadata
#[arg(short, long)]
key: Name,
/// A value of metadata
#[arg(short, long)]
value: ValueArg,
}

impl RunArgs for Set {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
id,
key,
value: ValueArg(value),
} = self;
let set_key_value = SetKeyValue::domain(id, key, value);
submit([set_key_value], UnlimitedMetadata::new(), context)
.wrap_err("Failed to submit Set instruction")
}
}

/// Remove metadata into domain by key
#[derive(Debug, Clone, clap::Args)]
pub struct Remove {
/// A domain id from which metadata is to be removed
#[arg(short, long)]
id: DomainId,
/// A key of metadata
#[arg(short, long)]
key: Name,
}

impl RunArgs for Remove {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self { id, key } = self;
let remove_key_value = RemoveKeyValue::domain(id, key);
submit([remove_key_value], UnlimitedMetadata::new(), context)
.wrap_err("Failed to submit Remove instruction")
}
}
}
}

mod account {
Expand Down

0 comments on commit 66072b4

Please sign in to comment.