-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdelete.rs
More file actions
53 lines (41 loc) · 1.28 KB
/
delete.rs
File metadata and controls
53 lines (41 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use clap::Args;
use ic_agent::AgentError;
use icp::context::{Context, GetAgentError, GetCanisterIdError};
use crate::commands::args;
#[derive(Debug, Args)]
pub(crate) struct DeleteArgs {
#[command(flatten)]
pub(crate) cmd_args: args::CanisterCommandArgs,
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum CommandError {
#[error(transparent)]
Delete(#[from] AgentError),
#[error(transparent)]
GetAgent(#[from] GetAgentError),
#[error(transparent)]
GetCanisterId(#[from] GetCanisterIdError),
}
pub(crate) async fn exec(ctx: &Context, args: &DeleteArgs) -> Result<(), CommandError> {
let selections = args.cmd_args.selections();
let agent = ctx
.get_agent(
&selections.identity,
&selections.network,
&selections.environment,
)
.await?;
let cid = ctx
.get_canister_id(
&selections.canister,
&selections.network,
&selections.environment,
)
.await?;
// Management Interface
let mgmt = ic_utils::interfaces::ManagementCanister::create(&agent);
// Instruct management canister to delete canister
mgmt.delete_canister(&cid).await?;
// TODO(or.ricon): Remove the canister association with the network/environment
Ok(())
}