module main import nspkg struct ConfigDeptest { pub mut: show_help bool @[long: help; short: h] query []string @[tail] } // unsatisfied_deps are the dependencies no installed package satisfies, in // the order and the spelling they were given fn unsatisfied_deps(pkgcache &nspkg.List, deps []string) []string { mut out := []string{} for dep in deps { if _ := pkgcache.find_satisfier(dep) { continue } out << dep } return out } // deptest is pacman's -T: it prints every dependency no installed package // satisfies and returns them; main exits 127 when there is one, the code // makepkg tells apart from a failure. it changes nothing, so it needs no root fn deptest(config ConfigDeptest) ![]string { need_query(config.query, 'dependency')! handle := nspkg.initialize(root_path, db_path) or { return err } defer { handle.release() or { went_on('release the nspkg handle', err) } } pkgcache := local_pkgcache(handle)! missing := unsatisfied_deps(pkgcache, config.query) if ipc_on() { emit(UnsatisfiedEvent{ deps: missing }) } else { for dep in missing { println(dep) } } // the defer above releases the handle; a second release here would free // it twice return missing }