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 unsafe_paths: report.unsafe_paths38 }))39 return 040 }41 ok('migrated ${fmt.plural(report.saves, 'save')} from Koh 2 (lane ${report.lane})')42 note('${report.checkpoints} checkpoints · ${report.flags} flags · ${report.objects} objects')43 warn_unsafe_paths(report.unsafe_paths)44 note('the Koh 2 data is untouched in ${migrate.archive_dir}/ — move it back to go back')45 if report.ignore_carried {46 note('carried the ignore rules to ${snapshot.ignore_file}')47 }48 if report.build_renamed {49 note('renamed kepr.build to koh.build, and saved that')50 }51 if report.log_md_was_tracked {52 warn('LOG.md was tracked by Koh 2; koh writes it itself now, so it is no longer snapshotted')53 }54 note('run "koh status" to see what the migration left, then "koh save"')55 if machine.has_remote() {56 note('this machine has a remote — run "koh offer" to publish the migrated history')57 }58 return 059}6061struct MigrateJson {62 repo string63 lane string64 saves int65 checkpoints int66 flags int67 objects int68 head string69 ignore_moved bool70 build_file bool71 unsafe_paths []string72}