123module cli45import json26import os7import src.fmt8import src.machine9import src.migrate10import src.snapshot1112pub fn cmd_migrate(raw []string) int {13 args := parse('migrate', raw, Options{14 values: ['lane']15 flags: ['json']16 }) or { return usage_error(err.msg()) }17 mut lane := args.value('lane')18 if lane == '' {19 lane = migrate.default_lane20 }21 if lane !in ['dev', 'main'] {22 return usage_error('--lane takes dev or main, not "${lane}"')23 }24 root := os.getwd()25 report := migrate.run(root, lane) or { return refuse(args.json(), err.msg()) }26 if args.json() {27 emit_json(json2.encode(MigrateJson{28 repo: report.root29 lane: report.lane30 saves: report.saves31 checkpoints: report.checkpoints32 flags: report.flags33 objects: report.objects34 head: report.head35 ignore_moved: report.ignore_carried36 build_file: report.build_renamed37 }))38 return 039 }40 ok('migrated ${fmt.plural(report.saves, 'save')} from Koh 2 (lane ${report.lane})')41 note('${report.checkpoints} checkpoints · ${report.flags} flags · ${report.objects} objects')42 note('the Koh 2 data is untouched in ${migrate.archive_dir}/ — move it back to go back')43 if report.ignore_carried {44 note('carried the ignore rules to ${snapshot.ignore_file}')45 }46 if report.build_renamed {47 note('renamed kepr.build to koh.build, and saved that')48 }49 if report.log_md_was_tracked {50 warn('LOG.md was tracked by Koh 2; koh writes it itself now, so it is no longer snapshotted')51 }52 note('run "koh status" to see what the migration left, then "koh save"')53 if machine.has_remote() {54 note('this machine has a remote — run "koh offer" to publish the migrated history')55 }56 return 057}5859struct MigrateJson {60 repo string61 lane string62 saves int63 checkpoints int64 flags int65 objects int66 head string67 ignore_moved bool68 build_file bool69}