mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 17:17:22 +01:00
8916cd174b
* rework relationship between runtime and cfg * separate runtime from cfg * simplify instantiation logic * move installer to appropriate package * move operator to sync package * add tests for srcinfo service * consolidate srcinfo service in sync * add logger to srcinfo * add logger to preparer * remove unused text functions * remove remaining text.* from srcinfo * remove global logger parts * remove global org method exports * remove global logger * move text->input * add rule to prevent fmt.Print * update golangci go version * remove outdated FAQs * remove outdated FAQs
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package runtime
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
|
|
|
pacmanconf "github.com/Morganamilo/go-pacmanconf"
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
func retrievePacmanConfig(cmdArgs *parser.Arguments, pacmanConfigPath string) (*pacmanconf.Config, bool, error) {
|
|
root := "/"
|
|
if value, _, exists := cmdArgs.GetArg("root", "r"); exists {
|
|
root = value
|
|
}
|
|
|
|
pacmanConf, stderr, err := pacmanconf.PacmanConf("--config", pacmanConfigPath, "--root", root)
|
|
if err != nil {
|
|
cmdErr := err
|
|
if stderr != "" {
|
|
cmdErr = fmt.Errorf("%w\n%s", err, stderr)
|
|
}
|
|
|
|
return nil, false, cmdErr
|
|
}
|
|
|
|
if dbPath, _, exists := cmdArgs.GetArg("dbpath", "b"); exists {
|
|
pacmanConf.DBPath = dbPath
|
|
}
|
|
|
|
if arch := cmdArgs.GetArgs("arch"); arch != nil {
|
|
pacmanConf.Architecture = append(pacmanConf.Architecture, arch...)
|
|
}
|
|
|
|
if ignoreArray := cmdArgs.GetArgs("ignore"); ignoreArray != nil {
|
|
pacmanConf.IgnorePkg = append(pacmanConf.IgnorePkg, ignoreArray...)
|
|
}
|
|
|
|
if ignoreGroupsArray := cmdArgs.GetArgs("ignoregroup"); ignoreGroupsArray != nil {
|
|
pacmanConf.IgnoreGroup = append(pacmanConf.IgnoreGroup, ignoreGroupsArray...)
|
|
}
|
|
|
|
if cacheArray := cmdArgs.GetArgs("cachedir"); cacheArray != nil {
|
|
pacmanConf.CacheDir = cacheArray
|
|
}
|
|
|
|
if gpgDir, _, exists := cmdArgs.GetArg("gpgdir"); exists {
|
|
pacmanConf.GPGDir = gpgDir
|
|
}
|
|
|
|
useColor := pacmanConf.Color && term.IsTerminal(int(os.Stdout.Fd()))
|
|
|
|
switch value, _, _ := cmdArgs.GetArg("color"); value {
|
|
case "always":
|
|
useColor = true
|
|
case "auto":
|
|
useColor = term.IsTerminal(int(os.Stdout.Fd()))
|
|
case "never":
|
|
useColor = false
|
|
}
|
|
|
|
return pacmanConf, useColor, nil
|
|
}
|