|
@@ -2,8 +2,6 @@ package main
|
|
|
|
|
|
import (
|
|
|
"bufio"
|
|
|
- "bytes"
|
|
|
- "encoding/json"
|
|
|
"fmt"
|
|
|
"os"
|
|
|
"os/exec"
|
|
@@ -13,6 +11,7 @@ import (
|
|
|
pacmanconf "github.com/Morganamilo/go-pacmanconf"
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
|
+ "github.com/Jguer/yay/v10/pkg/settings"
|
|
|
"github.com/Jguer/yay/v10/pkg/text"
|
|
|
)
|
|
|
|
|
@@ -24,12 +23,6 @@ const (
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- // Describes Sorting method for numberdisplay
|
|
|
- bottomUp = iota
|
|
|
- topDown
|
|
|
-)
|
|
|
-
|
|
|
-const (
|
|
|
modeAUR targetMode = iota
|
|
|
modeRepo
|
|
|
modeAny
|
|
@@ -37,53 +30,6 @@ const (
|
|
|
|
|
|
type targetMode int
|
|
|
|
|
|
-// Configuration stores yay's config.
|
|
|
-type Configuration struct {
|
|
|
- AURURL string `json:"aururl"`
|
|
|
- BuildDir string `json:"buildDir"`
|
|
|
- ABSDir string `json:"absdir"`
|
|
|
- Editor string `json:"editor"`
|
|
|
- EditorFlags string `json:"editorflags"`
|
|
|
- MakepkgBin string `json:"makepkgbin"`
|
|
|
- MakepkgConf string `json:"makepkgconf"`
|
|
|
- PacmanBin string `json:"pacmanbin"`
|
|
|
- PacmanConf string `json:"pacmanconf"`
|
|
|
- ReDownload string `json:"redownload"`
|
|
|
- ReBuild string `json:"rebuild"`
|
|
|
- AnswerClean string `json:"answerclean"`
|
|
|
- AnswerDiff string `json:"answerdiff"`
|
|
|
- AnswerEdit string `json:"answeredit"`
|
|
|
- AnswerUpgrade string `json:"answerupgrade"`
|
|
|
- GitBin string `json:"gitbin"`
|
|
|
- GpgBin string `json:"gpgbin"`
|
|
|
- GpgFlags string `json:"gpgflags"`
|
|
|
- MFlags string `json:"mflags"`
|
|
|
- SortBy string `json:"sortby"`
|
|
|
- SearchBy string `json:"searchby"`
|
|
|
- GitFlags string `json:"gitflags"`
|
|
|
- RemoveMake string `json:"removemake"`
|
|
|
- SudoBin string `json:"sudobin"`
|
|
|
- SudoFlags string `json:"sudoflags"`
|
|
|
- RequestSplitN int `json:"requestsplitn"`
|
|
|
- SearchMode int `json:"-"`
|
|
|
- SortMode int `json:"sortmode"`
|
|
|
- CompletionInterval int `json:"completionrefreshtime"`
|
|
|
- SudoLoop bool `json:"sudoloop"`
|
|
|
- TimeUpdate bool `json:"timeupdate"`
|
|
|
- NoConfirm bool `json:"-"`
|
|
|
- Devel bool `json:"devel"`
|
|
|
- CleanAfter bool `json:"cleanAfter"`
|
|
|
- Provides bool `json:"provides"`
|
|
|
- PGPFetch bool `json:"pgpfetch"`
|
|
|
- UpgradeMenu bool `json:"upgrademenu"`
|
|
|
- CleanMenu bool `json:"cleanmenu"`
|
|
|
- DiffMenu bool `json:"diffmenu"`
|
|
|
- EditMenu bool `json:"editmenu"`
|
|
|
- CombinedUpgrade bool `json:"combinedupgrade"`
|
|
|
- UseAsk bool `json:"useask"`
|
|
|
- BatchInstall bool `json:"batchinstall"`
|
|
|
-}
|
|
|
-
|
|
|
var yayVersion = "10.0.0"
|
|
|
|
|
|
var localePath = "/usr/share/locale"
|
|
@@ -113,7 +59,7 @@ var vcsFile string
|
|
|
var shouldSaveConfig bool
|
|
|
|
|
|
// YayConf holds the current config values for yay.
|
|
|
-var config *Configuration
|
|
|
+var config *settings.Configuration
|
|
|
|
|
|
// AlpmConf holds the current config values for pacman.
|
|
|
var pacmanConf *pacmanconf.Config
|
|
@@ -126,25 +72,8 @@ var mode = modeAny
|
|
|
|
|
|
var hideMenus = false
|
|
|
|
|
|
-// SaveConfig writes yay config to file.
|
|
|
-func (config *Configuration) saveConfig() error {
|
|
|
- marshalledinfo, err := json.MarshalIndent(config, "", "\t")
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- in, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- defer in.Close()
|
|
|
- if _, err = in.Write(marshalledinfo); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- return in.Sync()
|
|
|
-}
|
|
|
-
|
|
|
-func defaultSettings() *Configuration {
|
|
|
- newConfig := &Configuration{
|
|
|
+func defaultSettings() *settings.Configuration {
|
|
|
+ newConfig := &settings.Configuration{
|
|
|
AURURL: "https://aur.archlinux.org",
|
|
|
BuildDir: "$HOME/.cache/yay",
|
|
|
ABSDir: "$HOME/.cache/yay/abs",
|
|
@@ -161,7 +90,7 @@ func defaultSettings() *Configuration {
|
|
|
GpgFlags: "",
|
|
|
MFlags: "",
|
|
|
GitFlags: "",
|
|
|
- SortMode: bottomUp,
|
|
|
+ SortMode: settings.BottomUp,
|
|
|
CompletionInterval: 7,
|
|
|
SortBy: "votes",
|
|
|
SearchBy: "name-desc",
|
|
@@ -196,34 +125,6 @@ func defaultSettings() *Configuration {
|
|
|
return newConfig
|
|
|
}
|
|
|
|
|
|
-func (config *Configuration) expandEnv() {
|
|
|
- config.AURURL = os.ExpandEnv(config.AURURL)
|
|
|
- config.ABSDir = os.ExpandEnv(config.ABSDir)
|
|
|
- config.BuildDir = os.ExpandEnv(config.BuildDir)
|
|
|
- config.Editor = os.ExpandEnv(config.Editor)
|
|
|
- config.EditorFlags = os.ExpandEnv(config.EditorFlags)
|
|
|
- config.MakepkgBin = os.ExpandEnv(config.MakepkgBin)
|
|
|
- config.MakepkgConf = os.ExpandEnv(config.MakepkgConf)
|
|
|
- config.PacmanBin = os.ExpandEnv(config.PacmanBin)
|
|
|
- config.PacmanConf = os.ExpandEnv(config.PacmanConf)
|
|
|
- config.GpgFlags = os.ExpandEnv(config.GpgFlags)
|
|
|
- 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.GitBin = os.ExpandEnv(config.GitBin)
|
|
|
- config.GpgBin = os.ExpandEnv(config.GpgBin)
|
|
|
- config.SudoBin = os.ExpandEnv(config.SudoBin)
|
|
|
- config.SudoFlags = os.ExpandEnv(config.SudoFlags)
|
|
|
- config.ReDownload = os.ExpandEnv(config.ReDownload)
|
|
|
- config.ReBuild = os.ExpandEnv(config.ReBuild)
|
|
|
- config.AnswerClean = os.ExpandEnv(config.AnswerClean)
|
|
|
- config.AnswerDiff = os.ExpandEnv(config.AnswerDiff)
|
|
|
- config.AnswerEdit = os.ExpandEnv(config.AnswerEdit)
|
|
|
- config.AnswerUpgrade = os.ExpandEnv(config.AnswerUpgrade)
|
|
|
- config.RemoveMake = os.ExpandEnv(config.RemoveMake)
|
|
|
-}
|
|
|
-
|
|
|
// Editor returns the preferred system editor.
|
|
|
func editor() (editor string, args []string) {
|
|
|
switch {
|
|
@@ -334,16 +235,6 @@ func getInput(defaultValue string) (string, error) {
|
|
|
return string(buf), nil
|
|
|
}
|
|
|
|
|
|
-func (config *Configuration) String() string {
|
|
|
- var buf bytes.Buffer
|
|
|
- enc := json.NewEncoder(&buf)
|
|
|
- enc.SetIndent("", "\t")
|
|
|
- if err := enc.Encode(config); err != nil {
|
|
|
- fmt.Fprintln(os.Stderr, err)
|
|
|
- }
|
|
|
- return buf.String()
|
|
|
-}
|
|
|
-
|
|
|
func toUsage(usages []string) alpm.Usage {
|
|
|
if len(usages) == 0 {
|
|
|
return alpm.UsageAll
|