From 8bf3997c81db88d8401db28c86f701be014442c2 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 22 Nov 2024 21:05:20 -0600 Subject: [PATCH] repos.FindByName() --- common.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/common.go b/common.go index fafc11a..fd2edf8 100644 --- a/common.go +++ b/common.go @@ -25,7 +25,23 @@ func (r *RepoList) Hide() { } // better name: use this -func (r *RepoList) FindRepoByName(path string) *RepoRow { +// matches by path or by name +func (r *RepoList) FindByName(name string) *RepoRow { + loop := r.ReposSortByName() + for loop.Scan() { + repo := loop.Repo() + if repo.GoPath() == name { + return repo + } + base := filepath.Base(repo.GoPath()) + if base == name { + return repo + } + } + return nil +} + +func (r *RepoList) FindByPath(path string) *RepoRow { return r.FindRepo(path) }