mirror of
				https://github.com/Jguer/yay.git
				synced 2025-11-04 00:03:44 -05:00 
			
		
		
		
	`len` returns 0 if the slice or map is nil. From the Go specification [1]: "1. For a nil slice, the number of iterations is 0." "3. If the map is nil, the number of iterations is 0." Therefore, an additional `len(v) != 0` check for before the loop is unnecessary. [1]: https://go.dev/ref/spec#For_range Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
		
			
				
	
	
		
			81 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package main
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
	"fmt"
 | 
						|
	"net/http"
 | 
						|
	"os"
 | 
						|
	"strings"
 | 
						|
 | 
						|
	"github.com/Jguer/aur"
 | 
						|
	"github.com/leonelquinteros/gotext"
 | 
						|
 | 
						|
	"github.com/Jguer/yay/v12/pkg/download"
 | 
						|
	"github.com/Jguer/yay/v12/pkg/runtime"
 | 
						|
	"github.com/Jguer/yay/v12/pkg/settings/parser"
 | 
						|
	"github.com/Jguer/yay/v12/pkg/text"
 | 
						|
)
 | 
						|
 | 
						|
// yay -Gp.
 | 
						|
func printPkgbuilds(dbExecutor download.DBSearcher, aurClient aur.QueryClient,
 | 
						|
	httpClient *http.Client, logger *text.Logger, targets []string,
 | 
						|
	mode parser.TargetMode, aurURL string,
 | 
						|
) error {
 | 
						|
	pkgbuilds, err := download.PKGBUILDs(dbExecutor, aurClient, httpClient, logger, targets, aurURL, mode)
 | 
						|
	if err != nil {
 | 
						|
		logger.Errorln(err)
 | 
						|
	}
 | 
						|
 | 
						|
	for target, pkgbuild := range pkgbuilds {
 | 
						|
		logger.Printf("\n\n# %s\n\n%s", target, string(pkgbuild))
 | 
						|
	}
 | 
						|
 | 
						|
	if len(pkgbuilds) != len(targets) {
 | 
						|
		missing := []string{}
 | 
						|
 | 
						|
		for _, target := range targets {
 | 
						|
			if _, ok := pkgbuilds[target]; !ok {
 | 
						|
				missing = append(missing, target)
 | 
						|
			}
 | 
						|
		}
 | 
						|
 | 
						|
		logger.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
 | 
						|
 | 
						|
		return fmt.Errorf("")
 | 
						|
	}
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
// yay -G.
 | 
						|
func getPkgbuilds(ctx context.Context, dbExecutor download.DBSearcher, aurClient aur.QueryClient,
 | 
						|
	run *runtime.Runtime, targets []string, force bool,
 | 
						|
) error {
 | 
						|
	wd, err := os.Getwd()
 | 
						|
	if err != nil {
 | 
						|
		return err
 | 
						|
	}
 | 
						|
 | 
						|
	cloned, errD := download.PKGBUILDRepos(ctx, dbExecutor, aurClient,
 | 
						|
		run.CmdBuilder, run.Logger, targets, run.Cfg.Mode, run.Cfg.AURURL, wd, force)
 | 
						|
	if errD != nil {
 | 
						|
		run.Logger.Errorln(errD)
 | 
						|
	}
 | 
						|
 | 
						|
	if len(targets) != len(cloned) {
 | 
						|
		missing := []string{}
 | 
						|
 | 
						|
		for _, target := range targets {
 | 
						|
			if _, ok := cloned[target]; !ok {
 | 
						|
				missing = append(missing, target)
 | 
						|
			}
 | 
						|
		}
 | 
						|
 | 
						|
		run.Logger.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
 | 
						|
 | 
						|
		err = fmt.Errorf("")
 | 
						|
	}
 | 
						|
 | 
						|
	return err
 | 
						|
}
 |