Skip to content

Commit 6e622f7

Browse files
committed
use shared arg
1 parent 55cec52 commit 6e622f7

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

crates/icp-cli/src/commands/canister/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub(crate) mod stop;
1515
pub(crate) mod top_up;
1616

1717
#[derive(Debug, Subcommand)]
18+
#[allow(clippy::large_enum_variant)]
1819
pub(crate) enum Command {
1920
/// Make a canister call
2021
Call(call::CallArgs),

crates/icp-cli/src/commands/canister/settings/update.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ use byte_unit::{Byte, Unit};
44
use clap::{ArgAction, Args};
55
use ic_agent::{AgentError, export::Principal};
66
use ic_management_canister_types::{CanisterStatusResult, EnvironmentVariable, LogVisibility};
7-
use icp::{
8-
agent,
9-
identity::{self, IdentitySelection},
10-
network,
11-
};
7+
use icp::{agent, identity, network};
128

139
use crate::{
14-
commands::{Context, GetAgentForEnvError, GetCanisterIdForEnvError, GetEnvironmentError},
15-
options::{EnvironmentOpt, IdentityOpt},
10+
commands::{Context, GetAgentForEnvError, GetCanisterIdForEnvError, GetEnvironmentError, args},
1611
store_id::LookupError as LookupIdError,
1712
};
1813

@@ -78,14 +73,8 @@ impl EnvironmentVariableOpt {
7873

7974
#[derive(Debug, Args)]
8075
pub(crate) struct UpdateArgs {
81-
/// The name of the canister within the current project
82-
pub(crate) name: String,
83-
84-
#[command(flatten)]
85-
identity: IdentityOpt,
86-
8776
#[command(flatten)]
88-
environment: EnvironmentOpt,
77+
pub(crate) cmd_args: args::CanisterCommandArgs,
8978

9079
#[command(flatten)]
9180
controllers: Option<ControllerOpt>,
@@ -146,18 +135,13 @@ pub(crate) enum CommandError {
146135

147136
#[error(transparent)]
148137
GetCanisterIdForEnv(#[from] GetCanisterIdForEnvError),
138+
139+
#[error(transparent)]
140+
Shared(#[from] args::ArgValidationError),
149141
}
150142

151143
pub(crate) async fn exec(ctx: &Context, args: &UpdateArgs) -> Result<(), CommandError> {
152-
let identity_selection: IdentitySelection = args.identity.clone().into();
153-
let environment = args.environment.name();
154-
155-
// Agent
156-
let agent = ctx
157-
.get_agent_for_env(&identity_selection, environment)
158-
.await?;
159-
160-
let cid = ctx.get_canister_id_for_env(&args.name, environment).await?;
144+
let (cid, agent) = args.cmd_args.get_cid_and_agent(ctx).await?;
161145

162146
// Management Interface
163147
let mgmt = ic_utils::interfaces::ManagementCanister::create(&agent);

docs/cli-reference.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,17 @@ List the canisters in an environment
259259

260260
## `icp-cli canister settings update`
261261

262-
**Usage:** `icp-cli canister settings update [OPTIONS] <NAME>`
262+
**Usage:** `icp-cli canister settings update [OPTIONS] <CANISTER>`
263263

264264
###### **Arguments:**
265265

266-
* `<NAME>`The name of the canister within the current project
266+
* `<CANISTER>`Name or principal of canister to target When using a name an environment must be specified
267267

268268
###### **Options:**
269269

270+
* `--network <NETWORK>` — Name of the network to target
271+
* `--environment <ENVIRONMENT>` — Name of the target environment
270272
* `--identity <IDENTITY>` — The user identity to run this command as
271-
* `--environment <ENVIRONMENT>` — Override the environment to connect to. By default, the local environment is used
272-
* `--ic` — Shorthand for --environment=ic
273273
* `--add-controller <ADD_CONTROLLER>`
274274
* `--remove-controller <REMOVE_CONTROLLER>`
275275
* `--set-controller <SET_CONTROLLER>`

0 commit comments

Comments
 (0)