cmd_migrate.v

1.8 KB · raw

1//! `koh migrate` — one-time conversion from Koh 2.23module cli45import json6import 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(json.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		}))37		return 038	}39	ok('migrated ${fmt.plural(report.saves, 'save')} from Koh 2 (lane ${report.lane})')40	note('${report.checkpoints} checkpoints · ${report.flags} flags · ${report.objects} objects')41	note('the Koh 2 data is untouched in ${migrate.archive_dir}/ — move it back to go back')42	if report.ignore_carried {43		note('carried the ignore rules to ${snapshot.ignore_file}')44	}45	if report.log_md_was_tracked {46		warn('LOG.md was tracked by Koh 2; koh writes it itself now, so it is no longer snapshotted')47	}48	note('run "koh status" to see what the migration left, then "koh save"')49	if machine.has_remote() {50		note('this machine has a remote — run "koh offer" to publish the migrated history')51	}52	return 053}5455struct MigrateJson {56	repo         string57	lane         string58	saves        int59	checkpoints  int60	flags        int61	objects      int62	head         string63	ignore_moved bool64}