diff --git a/wit.go b/wit.go index 0f68aae..6a19efa 100644 --- a/wit.go +++ b/wit.go @@ -24,6 +24,57 @@ func (m *Machine) IsInstalled(name string) bool { return false } +func (m *Machine) FindInstalledByName(name string) *Package { + loop := m.Packages.SortByName() + for loop.Scan() { + p := loop.Package() + if name == p.Name { + // log.Info("package installed:", p.Name, p.Version, p.PkgName) + return p + } + } + + // log.Info("package not-installed:", name) + return nil +} + +// looks to see if any package matches a name and version +// if version == "", return the first name found +func (m *Machine) FindVersion(name string, version string) *Package { + // first check all installed versions + loop := m.Packages.SortByName() + for loop.Scan() { + p := loop.Package() + if name == p.Name { + if version == "" { + return p + } else { + if version == p.Version { + return p + } + } + } + } + + // check all wit packages + loop = m.Wit.SortByName() + for loop.Scan() { + p := loop.Package() + if name == p.Name { + if version == "" { + return p + } else { + if version == p.Version { + return p + } + } + } + } + + // log.Info("package not-installed:", name) + return nil +} + // read the package list file from mirrors.wit.com func (m *Machine) InitWit() error { if m.Wit == nil {