-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::commands::global; | ||
|
||
pub mod remove; | ||
|
||
#[derive(Debug, clap::Subcommand)] | ||
pub enum Cmd { | ||
/// Remove contract alias | ||
Remove(remove::Cmd), | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Remove(#[from] remove::Error), | ||
} | ||
|
||
impl Cmd { | ||
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> { | ||
match &self { | ||
Cmd::Remove(remove) => remove.run(global_args).await?, | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::fmt::Debug; | ||
|
||
use clap::{command, Parser}; | ||
|
||
use crate::commands::{config::network, global}; | ||
use crate::config::locator; | ||
use crate::print::Print; | ||
|
||
#[derive(Parser, Debug, Clone)] | ||
#[group(skip)] | ||
pub struct Cmd { | ||
#[command(flatten)] | ||
pub config_locator: locator::Args, | ||
|
||
#[command(flatten)] | ||
network: network::Args, | ||
|
||
/// The contract alias that will be removed. | ||
pub alias: String, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Locator(#[from] locator::Error), | ||
|
||
#[error(transparent)] | ||
Network(#[from] network::Error), | ||
|
||
#[error("no contract found with alias `{alias}`")] | ||
NoContract { alias: String }, | ||
} | ||
|
||
impl Cmd { | ||
#[allow(clippy::unused_async)] | ||
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> { | ||
let print = Print::new(global_args.quiet); | ||
let alias = &self.alias; | ||
let network = self.network.get(&self.config_locator)?; | ||
let network_passphrase = &network.network_passphrase; | ||
|
||
let Some(contract) = self | ||
.config_locator | ||
.get_contract_id(&self.alias, network_passphrase)? | ||
else { | ||
return Err(Error::NoContract { | ||
alias: alias.into(), | ||
}); | ||
}; | ||
|
||
print.infoln(format!( | ||
"Contract alias '{alias}' references {contract} on network '{network_passphrase}'" | ||
)); | ||
|
||
self.config_locator | ||
.remove_contract_id(&network.network_passphrase, alias)?; | ||
|
||
print.checkln(format!("Contract alias '{alias}' has been removed")); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters