2016-09-05 02:17:51 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RepoResult describes a Repository package
|
|
|
|
type RepoResult struct {
|
|
|
|
Description string
|
|
|
|
Repository string
|
|
|
|
Version string
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
// RepoSearch describes a Repository search
|
|
|
|
type RepoSearch struct {
|
|
|
|
Resultcount int
|
|
|
|
Results []RepoResult
|
|
|
|
}
|
|
|
|
|
|
|
|
func getInstalledPackage(pkg string) (err error) {
|
|
|
|
cmd := exec.Command(PacmanBin, "-Qi", pkg)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
err = cmd.Run()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// SearchPackages handles repo searches
|
|
|
|
func SearchPackages(pkg string) (search RepoSearch, err error) {
|
2016-09-06 21:22:20 +00:00
|
|
|
cmdOutput, err := exec.Command(PacmanBin, "-Ss", pkg).Output()
|
2016-09-05 02:17:51 +00:00
|
|
|
outputSlice := strings.Split(string(cmdOutput), "\n")
|
|
|
|
if outputSlice[0] == "" {
|
2016-09-07 09:10:04 +00:00
|
|
|
return search, nil
|
2016-09-05 02:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i := true
|
|
|
|
var tempStr string
|
|
|
|
var rRes *RepoResult
|
|
|
|
for _, pkgStr := range outputSlice {
|
|
|
|
if i {
|
|
|
|
rRes = new(RepoResult)
|
|
|
|
fmt.Sscanf(pkgStr, "%s %s\n", &tempStr, &rRes.Version)
|
|
|
|
repoNameSlc := strings.Split(tempStr, "/")
|
|
|
|
rRes.Repository = repoNameSlc[0]
|
|
|
|
rRes.Name = repoNameSlc[1]
|
|
|
|
i = false
|
|
|
|
} else {
|
|
|
|
rRes.Description = pkgStr
|
|
|
|
search.Resultcount++
|
|
|
|
search.Results = append(search.Results, *rRes)
|
|
|
|
i = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-09-07 09:10:04 +00:00
|
|
|
func isInRepo(pkg string) bool {
|
|
|
|
if _, err := exec.Command(PacmanBin, "-Sp", pkg).Output(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-09-05 02:17:51 +00:00
|
|
|
func (s RepoSearch) printSearch(index int) (err error) {
|
|
|
|
|
|
|
|
for i, result := range s.Results {
|
|
|
|
if index != SearchMode {
|
2016-09-07 09:10:04 +00:00
|
|
|
fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
2016-09-05 22:47:36 +00:00
|
|
|
i, result.Repository, result.Name, result.Version, result.Description)
|
2016-09-05 02:17:51 +00:00
|
|
|
} else {
|
2016-09-07 09:10:04 +00:00
|
|
|
fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
|
|
|
result.Repository, result.Name, result.Version, result.Description)
|
2016-09-05 02:17:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|