diff --git a/config.go b/config.go index 377e5d2c..fa854df1 100644 --- a/config.go +++ b/config.go @@ -56,6 +56,7 @@ type Configuration struct { GpgFlags string `json:"gpgflags"` MFlags string `json:"mflags"` SortBy string `json:"sortby"` + SearchBy string `json:"searchby"` GitFlags string `json:"gitflags"` RemoveMake string `json:"removemake"` RequestSplitN int `json:"requestsplitn"` @@ -157,6 +158,7 @@ func defaultSettings() *Configuration { SortMode: bottomUp, CompletionInterval: 7, SortBy: "votes", + SearchBy: "name-desc", SudoLoop: false, TarBin: "bsdtar", GitBin: "git", @@ -200,6 +202,7 @@ func (config *Configuration) expandEnv() { config.MFlags = os.ExpandEnv(config.MFlags) config.GitFlags = os.ExpandEnv(config.GitFlags) config.SortBy = os.ExpandEnv(config.SortBy) + config.SearchBy = os.ExpandEnv(config.SearchBy) config.TarBin = os.ExpandEnv(config.TarBin) config.GitBin = os.ExpandEnv(config.GitBin) config.GpgBin = os.ExpandEnv(config.GpgBin) diff --git a/depPool.go b/depPool.go index cc108fdd..e02588e7 100644 --- a/depPool.go +++ b/depPool.go @@ -188,7 +188,7 @@ func (dp *depPool) findProvides(pkgs types.StringSet) error { words := strings.Split(pkg, "-") for i := range words { - results, err = rpc.SearchByNameDesc(strings.Join(words[:i+1], "-")) + results, err = rpc.Search(strings.Join(words[:i+1], "-")) if err == nil { break } diff --git a/go.mod b/go.mod index f7d22314..c1f22903 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module github.com/Jguer/yay/v9 require ( - github.com/Jguer/go-alpm v0.0.0-20190302211415-9c82d5170ce0 + github.com/Jguer/go-alpm v0.0.0-20190627095237-ec8523c9bb21 github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f github.com/Morganamilo/go-srcinfo v1.0.0 - github.com/mikkeloscar/aur v0.0.0-20181111113612-b71516da3ae9 + github.com/mikkeloscar/aur v0.0.0-20190912174111-183f80a38525 ) go 1.13 diff --git a/go.sum b/go.sum index 59b0f396..61701816 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,12 @@ github.com/Jguer/go-alpm v0.0.0-20190302211415-9c82d5170ce0 h1:jkaSC1289bzjkoc1qRMDrl4Oad2uoERHHqpptYsGIJY= github.com/Jguer/go-alpm v0.0.0-20190302211415-9c82d5170ce0/go.mod h1:FyxWWXMCnKWSU8prNG5ryzjilFJVj6PUr6yMR36rALA= +github.com/Jguer/go-alpm v0.0.0-20190627095237-ec8523c9bb21 h1:byeuFn/If54Ty6HzKeKlwTPIUKSag/aZTNcPLZsp1ms= +github.com/Jguer/go-alpm v0.0.0-20190627095237-ec8523c9bb21/go.mod h1:D5SUcIS9Yiz/L8cjRzq/992eERnx6ugYmGlc4e7xdus= github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f h1:ptFKynTV1p8JCzqk81NcMj0DV0Xle+PdKxfHjPbdIOU= github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f/go.mod h1:Hk55m330jNiwxRodIlMCvw5iEyoRUCIY64W1p9D+tHc= github.com/Morganamilo/go-srcinfo v1.0.0 h1:Wh4nEF+HJWo+29hnxM18Q2hi+DUf0GejS13+Wg+dzmI= github.com/Morganamilo/go-srcinfo v1.0.0/go.mod h1:MP6VGY1NNpVUmYIEgoM9acix95KQqIRyqQ0hCLsyYUY= github.com/mikkeloscar/aur v0.0.0-20181111113612-b71516da3ae9 h1:g4TBYa1sjv/TZfU9t82oYlRneu8cCVr3dnazE7os5vw= github.com/mikkeloscar/aur v0.0.0-20181111113612-b71516da3ae9/go.mod h1:n1NKHoldRNhIEufSx1PiDYcd2W+wpbz5/5K+p2eNDVk= +github.com/mikkeloscar/aur v0.0.0-20190912174111-183f80a38525 h1:T0cWcTw55+0h3bEBHWkDPEKYutNIksrDU4aJfkBJTpo= +github.com/mikkeloscar/aur v0.0.0-20190912174111-183f80a38525/go.mod h1:nYOKcK8tIj69ZZ8uDOWoiT+L25NvlOQaraDqTec/idA= diff --git a/parser.go b/parser.go index fc3d4a06..3003ef4a 100644 --- a/parser.go +++ b/parser.go @@ -378,6 +378,7 @@ func isArg(arg string) bool { case "bottomup": case "completioninterval": case "sortby": + case "searchby": case "redownload": case "redownloadall": case "noredownload": @@ -473,6 +474,8 @@ func handleConfig(option, value string) bool { } case "sortby": config.SortBy = value + case "searchby": + config.SearchBy = value case "noconfirm": config.NoConfirm = true case "config": @@ -677,6 +680,7 @@ func hasParam(arg string) bool { case "answerupgrade": case "completioninterval": case "sortby": + case "searchby": default: return false } diff --git a/query.go b/query.go index 1fa77e9e..cbf73795 100644 --- a/query.go +++ b/query.go @@ -101,18 +101,39 @@ func filterPackages() (local []alpm.Package, remote []alpm.Package, return } +func getSearchBy(value string) rpc.By { + switch value { + case "name": + return rpc.Name + case "maintainer": + return rpc.Maintainer + case "depends": + return rpc.Depends + case "makedepends": + return rpc.MakeDepends + case "optdepends": + return rpc.OptDepends + case "checkdepends": + return rpc.CheckDepends + default: + return rpc.NameDesc + } +} + // NarrowSearch searches AUR and narrows based on subarguments func narrowSearch(pkgS []string, sortS bool) (aurQuery, error) { var r []rpc.Pkg var err error var usedIndex int + by := getSearchBy(config.SearchBy) + if len(pkgS) == 0 { return nil, nil } for i, word := range pkgS { - r, err = rpc.Search(word) + r, err = rpc.SearchBy(word, by) if err == nil { usedIndex = i break diff --git a/vendor/github.com/Jguer/go-alpm/package.go b/vendor/github.com/Jguer/go-alpm/package.go index 91811e16..920975bc 100644 --- a/vendor/github.com/Jguer/go-alpm/package.go +++ b/vendor/github.com/Jguer/go-alpm/package.go @@ -181,6 +181,11 @@ func (pkg *Package) Files() []File { return convertFilelist(cFiles) } +// ContainsFile checks if the path is in the package filelist +func (pkg *Package) ContainsFile(path string) (File, error) { + return convertFile(C.alpm_filelist_contains(C.alpm_pkg_get_files(pkg.pmpkg), C.CString(path))) +} + // Groups returns the groups the package belongs to. func (pkg *Package) Groups() StringList { ptr := unsafe.Pointer(C.alpm_pkg_get_groups(pkg.pmpkg)) diff --git a/vendor/github.com/Jguer/go-alpm/types.go b/vendor/github.com/Jguer/go-alpm/types.go index 8b882c40..b09720a7 100644 --- a/vendor/github.com/Jguer/go-alpm/types.go +++ b/vendor/github.com/Jguer/go-alpm/types.go @@ -11,6 +11,7 @@ package alpm import "C" import ( + "errors" "fmt" "reflect" "unsafe" @@ -68,6 +69,16 @@ type File struct { Mode uint32 } +func convertFile(file *C.alpm_file_t) (File, error) { + if file == nil { + return File{}, errors.New("No file") + } + return File{ + Name: C.GoString(file.name), + Size: int64(file.size), + Mode: uint32(file.mode)}, nil +} + func convertFilelist(files *C.alpm_filelist_t) []File { size := int(files.count) items := make([]File, size) @@ -80,10 +91,9 @@ func convertFilelist(files *C.alpm_filelist_t) []File { cFiles := *(*[]C.alpm_file_t)(unsafe.Pointer(&rawItems)) for i := 0; i < size; i++ { - items[i] = File{ - Name: C.GoString(cFiles[i].name), - Size: int64(cFiles[i].size), - Mode: uint32(cFiles[i].mode)} + if file, err := convertFile(&cFiles[i]); err == nil { + items[i] = file + } } return items } diff --git a/vendor/github.com/mikkeloscar/aur/aur.go b/vendor/github.com/mikkeloscar/aur/aur.go index 5c7eb93b..7feb3885 100644 --- a/vendor/github.com/mikkeloscar/aur/aur.go +++ b/vendor/github.com/mikkeloscar/aur/aur.go @@ -18,6 +18,40 @@ type response struct { Results []Pkg `json:"results"` } +//By specifies what to seach by in RPC searches +type By int + +const ( + Name By = iota + NameDesc + Maintainer + Depends + MakeDepends + OptDepends + CheckDepends +) + +func (by By) String() string { + switch by { + case Name: + return "name" + case NameDesc: + return "name-desc" + case Maintainer: + return "maintainer" + case Depends: + return "depends" + case MakeDepends: + return "makedepends" + case OptDepends: + return "optdepends" + case CheckDepends: + return "checkdepends" + default: + panic("invalid By") + } +} + // Pkg holds package information type Pkg struct { ID int `json:"ID"` @@ -52,6 +86,11 @@ func get(values url.Values) ([]Pkg, error) { if err != nil { return nil, err } + + if resp.StatusCode == http.StatusServiceUnavailable { + return nil, errors.New("AUR is unavailable at this moment") + } + defer resp.Body.Close() dec := json.NewDecoder(resp.Body) @@ -80,50 +119,19 @@ func searchBy(query, by string) ([]Pkg, error) { return get(v) } -// Search searches for packages by the RPC's default defautl field. -// This is the same as SearchByNameDesc +// Search searches for packages using the RPC's default search by. +// This is the same as using SearchBy With NameDesc func Search(query string) ([]Pkg, error) { return searchBy(query, "") } -// Search searches for packages by package name. -func SearchByName(query string) ([]Pkg, error) { - return searchBy(query, "name") +// SearchBy searches for packages with a specified search by +func SearchBy(query string, by By) ([]Pkg, error) { + return searchBy(query, by.String()) } -// SearchByNameDesc searches for package by package name and description. -func SearchByNameDesc(query string) ([]Pkg, error) { - return searchBy(query, "name-desc") -} - -// SearchByMaintainer searches for package by maintainer. -func SearchByMaintainer(query string) ([]Pkg, error) { - return searchBy(query, "maintainer") -} - -// SearchByDepends searches for packages that depend on query -func SearchByDepends(query string) ([]Pkg, error) { - return searchBy(query, "depends") -} - -// SearchByMakeDepends searches for packages that makedepend on query -func SearchByMakeDepends(query string) ([]Pkg, error) { - return searchBy(query, "makedepends") -} - -// SearchByOptDepends searches for packages that optdepend on query -func SearchByOptDepends(query string) ([]Pkg, error) { - return searchBy(query, "optdepends") -} - -// SearchByCheckDepends searches for packages that checkdepend on query -func SearchByCheckDepends(query string) ([]Pkg, error) { - return searchBy(query, "checkdepends") -} - -// Orphans returns all orphan packages in the AUR. func Orphans() ([]Pkg, error) { - return SearchByMaintainer("") + return SearchBy("", Maintainer) } // Info shows info for one or multiple packages. diff --git a/vendor/modules.txt b/vendor/modules.txt index d880e8d0..b98b9a33 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,9 +1,9 @@ -# github.com/Jguer/go-alpm v0.0.0-20190302211415-9c82d5170ce0 +# github.com/Jguer/go-alpm v0.0.0-20190627095237-ec8523c9bb21 github.com/Jguer/go-alpm # github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f github.com/Morganamilo/go-pacmanconf github.com/Morganamilo/go-pacmanconf/ini # github.com/Morganamilo/go-srcinfo v1.0.0 github.com/Morganamilo/go-srcinfo -# github.com/mikkeloscar/aur v0.0.0-20181111113612-b71516da3ae9 +# github.com/mikkeloscar/aur v0.0.0-20190912174111-183f80a38525 github.com/mikkeloscar/aur