@@ -10,6 +10,7 @@ use icp::context::Context;
1010use icp_canister_interfaces:: nns_migration:: { MigrationStatus , NNS_MIGRATION_PRINCIPAL } ;
1111use indicatif:: { ProgressBar , ProgressStyle } ;
1212use num_traits:: ToPrimitive ;
13+ use tracing:: { info, warn} ;
1314
1415use crate :: commands:: args:: { self , Canister } ;
1516use crate :: operations:: canister_migration:: {
@@ -87,12 +88,12 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
8788 if !args. resume_watch {
8889 let can_confirm = stdin ( ) . is_terminal ( ) ;
8990 if !args. yes && can_confirm {
90- ctx . term . write_line ( & format ! (
91+ info ! (
9192 "This will migrate canister '{source_name}' ({source_cid}) to replace '{target_name}' ({target_cid})."
92- ) ) ? ;
93- ctx . term . write_line (
94- "The target canister will be deleted and the source canister will take over its ID." ,
95- ) ? ;
93+ ) ;
94+ info ! (
95+ "The target canister will be deleted and the source canister will take over its ID."
96+ ) ;
9697
9798 let confirmed = Confirm :: new ( )
9899 . with_prompt ( "Do you want to proceed?" )
@@ -136,11 +137,8 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
136137
137138 if !args. yes && cycles > WARN_CYCLES_THRESHOLD {
138139 if can_confirm {
139- ctx. term . write_line ( & format ! (
140- "Warning: Canister '{source_name}' has more than 15T cycles ({cycles} cycles)."
141- ) ) ?;
142- ctx. term
143- . write_line ( "The extra cycles will get burned during the migration." ) ?;
140+ warn ! ( "Canister '{source_name}' has more than 15T cycles ({cycles} cycles)." ) ;
141+ warn ! ( "The extra cycles will get burned during the migration." ) ;
144142
145143 let confirmed = Confirm :: new ( )
146144 . with_prompt ( "Do you want to proceed?" )
@@ -178,20 +176,16 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
178176 ) ;
179177 }
180178
181- ctx . term . write_line ( & format ! (
179+ info ! (
182180 "Migrating canister '{source_name}' ({source_cid}) to replace '{target_name}' ({target_cid})"
183- ) ) ?;
184- ctx. term
185- . write_line ( & format ! ( " Source subnet: {source_subnet}" ) ) ?;
186- ctx. term
187- . write_line ( & format ! ( " Target subnet: {target_subnet}" ) ) ?;
181+ ) ;
182+ info ! ( " Source subnet: {source_subnet}" ) ;
183+ info ! ( " Target subnet: {target_subnet}" ) ;
188184
189185 // Add NNS migration canister as controller to both canisters if not already
190186 let source_controllers = source_status. settings . controllers ;
191187 if !source_controllers. contains ( & NNS_MIGRATION_PRINCIPAL ) {
192- ctx. term . write_line ( & format ! (
193- "Adding NNS migration canister as controller of '{source_name}'..."
194- ) ) ?;
188+ info ! ( "Adding NNS migration canister as controller of '{source_name}'..." ) ;
195189 let mut new_controllers = source_controllers;
196190 new_controllers. push ( NNS_MIGRATION_PRINCIPAL ) ;
197191 let mut builder = mgmt. update_settings ( & source_cid) ;
@@ -203,9 +197,7 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
203197
204198 let target_controllers = target_status. settings . controllers ;
205199 if !target_controllers. contains ( & NNS_MIGRATION_PRINCIPAL ) {
206- ctx. term . write_line ( & format ! (
207- "Adding NNS migration canister as controller of '{target_name}'..."
208- ) ) ?;
200+ info ! ( "Adding NNS migration canister as controller of '{target_name}'..." ) ;
209201 let mut new_controllers = target_controllers;
210202 new_controllers. push ( NNS_MIGRATION_PRINCIPAL ) ;
211203 let mut builder = mgmt. update_settings ( & target_cid) ;
@@ -216,12 +208,12 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
216208 }
217209
218210 // Initiate migration
219- ctx . term . write_line ( "Initiating canister ID migration..." ) ? ;
211+ info ! ( "Initiating canister ID migration..." ) ;
220212 migrate_canister ( & agent, source_cid, target_cid) . await ?;
221213 } else {
222- ctx . term . write_line ( & format ! (
214+ info ! (
223215 "Resuming watch for migration of '{source_name}' ({source_cid}) to '{target_name}' ({target_cid})"
224- ) ) ? ;
216+ ) ;
225217 }
226218
227219 // Create spinner for polling
@@ -246,12 +238,12 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
246238 spinner. finish_with_message ( format ! (
247239 "Migration in progress: {status} (exiting early due to --skip-watch)"
248240 ) ) ;
249- ctx . term . write_line ( & format ! (
241+ info ! (
250242 "The source canister '{source_name}' has been deleted. Migration will continue in the background."
251- ) ) ? ;
252- ctx . term . write_line ( & format ! (
243+ ) ;
244+ info ! (
253245 "Use `icp canister migrate-id {source_name} --replace {target_name} --resume-watch` to monitor completion."
254- ) ) ? ;
246+ ) ;
255247 return Ok ( ( ) ) ;
256248 }
257249 }
@@ -286,9 +278,9 @@ pub(crate) async fn exec(ctx: &Context, args: &MigrateIdArgs) -> Result<(), anyh
286278 }
287279 }
288280
289- ctx . term . write_line ( & format ! (
281+ info ! (
290282 "Canister '{source_name}' ({source_cid}) has been successfully migrated to the new subnet, replacing {target_cid}"
291- ) ) ? ;
283+ ) ;
292284
293285 Ok ( ( ) )
294286}
0 commit comments