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 os.execvp(target, argv) or {36 eprintln(' ${fmt.red(fmt.glyph_fail)} could not hand this command to ${target}: ${err.msg()}')37 exit(1)38 }39}4041424344fn koh2_binary() string {45 if found := os.find_abs_path_of_executable('koh2') {46 return found47 }48 if legacy := os.find_abs_path_of_executable('koh') {49 if os.real_path(legacy) != os.real_path(os.executable()) {50 return legacy51 }52 }53 return ''54}55565758fn inside_koh2_repo(start string) bool {59 mut dir := os.real_path(start)60 for {61 path := os.join_path(dir, '.koh')62 if os.is_dir(path) {63 return true64 }65 if os.is_file(path) {66 return false67 }68 parent := os.dir(dir)69 if parent == dir || parent == '' {70 return false71 }72 dir = parent73 }74 return false75}