diff --git a/CHANGELOG.md b/CHANGELOG.md index ff0f217e..a760891a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +* feat!: Remove `--set-controller` and replace with a new flag `--remove-all-controllers`. For the old behavior, combine this flag with `--add-controller` * fix: Duplicate identities no longer cause an error when starting a network # v0.2.1-beta.0 diff --git a/crates/icp-cli/src/commands/canister/settings/update.rs b/crates/icp-cli/src/commands/canister/settings/update.rs index 4c60f534..ed47faf2 100644 --- a/crates/icp-cli/src/commands/canister/settings/update.rs +++ b/crates/icp-cli/src/commands/canister/settings/update.rs @@ -15,26 +15,27 @@ use crate::commands::args; #[derive(Clone, Debug, Default, Args)] pub(crate) struct ControllerOpt { /// Add one or more principals to the canister's controller list. - #[arg(long, action = ArgAction::Append, conflicts_with("set_controller"))] + #[arg(long, action = ArgAction::Append)] add_controller: Option>, /// Remove one or more principals from the canister's controller list. /// /// Warning: Removing yourself will cause you to lose control of the canister. - #[arg(long, action = ArgAction::Append, conflicts_with("set_controller"))] + #[arg(long, action = ArgAction::Append)] remove_controller: Option>, - /// Replace the canister's controller list with the specified principals. + /// Remove all controllers. /// - /// Warning: This removes all existing controllers not in the new list. - /// If you don't include yourself, you will lose control of the canister. - #[arg(long, action = ArgAction::Append)] - set_controller: Option>, + /// Warning: This will cause you to lose control of the canister, unless you + /// add your user principal back in `--add-controller` in the same command. + #[arg(long, conflicts_with = "remove_controller")] + remove_all_controllers: bool, } impl ControllerOpt { pub(crate) fn require_current_settings(&self) -> bool { - self.add_controller.is_some() || self.remove_controller.is_some() + !self.remove_all_controllers + && (self.add_controller.is_some() || self.remove_controller.is_some()) } } @@ -344,9 +345,7 @@ fn get_controllers( controllers: &ControllerOpt, current_status: Option<&CanisterStatusResult>, ) -> Option> { - if let Some(controllers) = controllers.set_controller.as_ref() { - return Some(controllers.clone()); - } else if controllers.require_current_settings() { + if controllers.require_current_settings() { let mut current_controllers: HashSet = current_status .as_ref() .expect("current status should be ready") @@ -365,10 +364,12 @@ fn get_controllers( } } - return Some(current_controllers.into_iter().collect::>()); + Some(current_controllers.into_iter().collect::>()) + } else if controllers.remove_all_controllers { + Some(controllers.add_controller.clone().unwrap_or_default()) + } else { + None } - - None } fn get_log_visibility( diff --git a/crates/icp-cli/tests/canister_settings_tests.rs b/crates/icp-cli/tests/canister_settings_tests.rs index 16300351..45cd4636 100644 --- a/crates/icp-cli/tests/canister_settings_tests.rs +++ b/crates/icp-cli/tests/canister_settings_tests.rs @@ -282,9 +282,10 @@ async fn canister_settings_update_controllers() { "--environment", "random-environment", "--force", - "--set-controller", + "--remove-all-controllers", + "--add-controller", principal_alice.as_str(), - "--set-controller", + "--add-controller", principal_bob.as_str(), ]) .assert() diff --git a/docs/reference/cli.md b/docs/reference/cli.md index a98e5129..b4d00460 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -442,9 +442,9 @@ Change a canister's settings to specified values * `--remove-controller ` — Remove one or more principals from the canister's controller list. Warning: Removing yourself will cause you to lose control of the canister. -* `--set-controller ` — Replace the canister's controller list with the specified principals. +* `--remove-all-controllers` — Remove all controllers. - Warning: This removes all existing controllers not in the new list. If you don't include yourself, you will lose control of the canister. + Warning: This will cause you to lose control of the canister, unless you add your user principal back in `--add-controller` in the same command. * `--compute-allocation ` * `--memory-allocation ` — Memory allocation in bytes. Supports suffixes: kb, kib, mb, mib, gb, gib (e.g. "4gib" or "2.5kb") * `--freezing-threshold ` — Freezing threshold. Controls how long a canister can be inactive before being frozen. Supports duration suffixes: s (seconds), m (minutes), h (hours), d (days), w (weeks). A bare number is treated as seconds