1234567891011module cli1213import os14import src.fmt15161718pub fn hand_over(argv []string) {19 if argv.len < 2 {20 return21 }22 command := argv[1]23 if command in ['migrate', 'man', 'help', '--help', '-h', '--version', '-v'] {24 return25 }26 if !inside_koh2_repo(os.getwd()) {27 return28 }29 target := koh2_binary()30 if target == '' {31 eprintln(' ${fmt.red(fmt.glyph_fail)} this folder holds a Koh 2 repo, and koh2 is not on PATH')32 eprintln(' install koh2, or run "koh migrate" to convert this repo')33 exit(1)34 }35 36 37 os.execvp(target, argv[1..]) or {38 eprintln(' ${fmt.red(fmt.glyph_fail)} could not hand this command to ${target}: ${err.msg()}')39 exit(1)40 }41}4243444546fn koh2_binary() string {47 if found := os.find_abs_path_of_executable('koh2') {48 return found49 }50 if legacy := os.find_abs_path_of_executable('koh') {51 if os.real_path(legacy) != os.real_path(os.executable()) {52 return legacy53 }54 }55 return ''56}57585960fn inside_koh2_repo(start string) bool {61 mut dir := os.real_path(start)62 for {63 path := os.join_path(dir, '.koh')64 if os.is_dir(path) {65 return true66 }67 if os.is_file(path) {68 return false69 }70 parent := os.dir(dir)71 if parent == dir || parent == '' {72 return false73 }74 dir = parent75 }76 return false77}