mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
Only minor changes
This commit is contained in:
parent
892d9cc752
commit
29f3e011ec
@ -10,13 +10,15 @@ import (
|
||||
)
|
||||
|
||||
func questionCallback(question alpm.QuestionAny) {
|
||||
qi, err := question.QuestionInstallIgnorepkg()
|
||||
if err == nil {
|
||||
if qi, err := question.QuestionInstallIgnorepkg(); err == nil {
|
||||
qi.SetInstall(true)
|
||||
}
|
||||
|
||||
qp, err := question.QuestionSelectProvider()
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
size := 0
|
||||
|
||||
qp.Providers(alpmHandle).ForEach(func(pkg alpm.Package) error {
|
||||
@ -83,5 +85,4 @@ func questionCallback(question alpm.QuestionAny) {
|
||||
qp.SetUseIndex(num - 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
24
clean.go
24
clean.go
@ -14,8 +14,7 @@ func removeVCSPackage(pkgs []string) {
|
||||
updated := false
|
||||
|
||||
for _, pkgName := range pkgs {
|
||||
_, ok := savedInfo[pkgName]
|
||||
if ok {
|
||||
if _, ok := savedInfo[pkgName]; ok {
|
||||
delete(savedInfo, pkgName)
|
||||
updated = true
|
||||
}
|
||||
@ -34,10 +33,10 @@ func cleanDependencies(removeOptional bool) error {
|
||||
}
|
||||
|
||||
if len(hanging) != 0 {
|
||||
err = cleanRemove(hanging)
|
||||
return cleanRemove(hanging)
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// CleanRemove sends a full removal command to pacman with the pkgName slice
|
||||
@ -49,8 +48,8 @@ func cleanRemove(pkgNames []string) (err error) {
|
||||
arguments := makeArguments()
|
||||
arguments.addArg("R")
|
||||
arguments.addTarget(pkgNames...)
|
||||
err = show(passToPacman(arguments))
|
||||
return err
|
||||
|
||||
return show(passToPacman(arguments))
|
||||
}
|
||||
|
||||
func syncClean(parser *arguments) error {
|
||||
@ -69,8 +68,7 @@ func syncClean(parser *arguments) error {
|
||||
}
|
||||
|
||||
if mode == ModeRepo || mode == ModeAny {
|
||||
err = show(passToPacman(parser))
|
||||
if err != nil {
|
||||
if err = show(passToPacman(parser)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -86,8 +84,7 @@ func syncClean(parser *arguments) error {
|
||||
question = "Do you want to remove all other AUR packages from cache?"
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Printf("Build directory: %s\n", config.BuildDir)
|
||||
fmt.Printf("\nBuild directory: %s\n", config.BuildDir)
|
||||
|
||||
if continueTask(question, true) {
|
||||
err = cleanAUR(keepInstalled, keepCurrent, removeAll)
|
||||
@ -98,10 +95,10 @@ func syncClean(parser *arguments) error {
|
||||
}
|
||||
|
||||
if continueTask("Do you want to remove ALL untracked AUR files?", true) {
|
||||
err = cleanUntracked()
|
||||
return cleanUntracked()
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
|
||||
@ -192,8 +189,7 @@ func cleanUntracked() error {
|
||||
dir := filepath.Join(config.BuildDir, file.Name())
|
||||
|
||||
if shouldUseGit(dir) {
|
||||
err = show(passToGit(dir, "clean", "-fx"))
|
||||
if err != nil {
|
||||
if err = show(passToGit(dir, "clean", "-fx")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
127
cmd.go
127
cmd.go
@ -171,15 +171,10 @@ func handleCmd() (err error) {
|
||||
}
|
||||
|
||||
func handleQuery() error {
|
||||
var err error
|
||||
|
||||
if cmdArgs.existsArg("u", "upgrades") {
|
||||
err = printUpdateList(cmdArgs)
|
||||
} else {
|
||||
err = show(passToPacman(cmdArgs))
|
||||
return printUpdateList(cmdArgs)
|
||||
}
|
||||
|
||||
return err
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
|
||||
func handleHelp() error {
|
||||
@ -187,7 +182,6 @@ func handleHelp() error {
|
||||
usage()
|
||||
return nil
|
||||
}
|
||||
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
|
||||
@ -289,8 +283,7 @@ func handleConfig(option, value string) bool {
|
||||
case "gpg":
|
||||
config.GpgBin = value
|
||||
case "requestsplitn":
|
||||
n, err := strconv.Atoi(value)
|
||||
if err == nil && n > 0 {
|
||||
if n, err := strconv.Atoi(value); err == nil && n > 0 {
|
||||
config.RequestSplitN = n
|
||||
}
|
||||
case "sudoloop":
|
||||
@ -340,9 +333,10 @@ func handleConfig(option, value string) bool {
|
||||
case "askremovemake":
|
||||
config.RemoveMake = "ask"
|
||||
default:
|
||||
// the option was not handled by the switch
|
||||
return false
|
||||
}
|
||||
|
||||
// the option was successfully handled by the switch
|
||||
return true
|
||||
}
|
||||
|
||||
@ -373,35 +367,33 @@ func handlePrint() (err error) {
|
||||
default:
|
||||
err = nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func handleYay() (err error) {
|
||||
func handleYay() error {
|
||||
//_, options, targets := cmdArgs.formatArgs()
|
||||
if cmdArgs.existsArg("gendb") {
|
||||
err = createDevelDB()
|
||||
} else if cmdArgs.existsDouble("c") {
|
||||
err = cleanDependencies(true)
|
||||
} else if cmdArgs.existsArg("c", "clean") {
|
||||
err = cleanDependencies(false)
|
||||
} else if len(cmdArgs.targets) > 0 {
|
||||
err = handleYogurt()
|
||||
return createDevelDB()
|
||||
}
|
||||
|
||||
return
|
||||
if cmdArgs.existsDouble("c") {
|
||||
return cleanDependencies(true)
|
||||
}
|
||||
if cmdArgs.existsArg("c", "clean") {
|
||||
return cleanDependencies(false)
|
||||
}
|
||||
if len(cmdArgs.targets) > 0 {
|
||||
return handleYogurt()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleGetpkgbuild() (err error) {
|
||||
err = getPkgbuilds(cmdArgs.targets)
|
||||
return
|
||||
func handleGetpkgbuild() error {
|
||||
return getPkgbuilds(cmdArgs.targets)
|
||||
}
|
||||
|
||||
func handleYogurt() (err error) {
|
||||
func handleYogurt() error {
|
||||
config.SearchMode = NumberMenu
|
||||
err = numberMenu(cmdArgs.targets)
|
||||
|
||||
return
|
||||
return numberMenu(cmdArgs.targets)
|
||||
}
|
||||
|
||||
func handleSync() (err error) {
|
||||
@ -413,44 +405,50 @@ func handleSync() (err error) {
|
||||
} else {
|
||||
config.SearchMode = Detailed
|
||||
}
|
||||
|
||||
err = syncSearch(targets)
|
||||
} else if cmdArgs.existsArg("p", "print", "print-format") {
|
||||
err = show(passToPacman(cmdArgs))
|
||||
} else if cmdArgs.existsArg("c", "clean") {
|
||||
err = syncClean(cmdArgs)
|
||||
} else if cmdArgs.existsArg("l", "list") {
|
||||
err = show(passToPacman(cmdArgs))
|
||||
} else if cmdArgs.existsArg("g", "groups") {
|
||||
err = show(passToPacman(cmdArgs))
|
||||
} else if cmdArgs.existsArg("i", "info") {
|
||||
err = syncInfo(targets)
|
||||
} else if cmdArgs.existsArg("u", "sysupgrade") {
|
||||
err = install(cmdArgs)
|
||||
} else if len(cmdArgs.targets) > 0 {
|
||||
err = install(cmdArgs)
|
||||
} else if cmdArgs.existsArg("y", "refresh") {
|
||||
err = show(passToPacman(cmdArgs))
|
||||
return syncSearch(targets)
|
||||
}
|
||||
|
||||
return
|
||||
if cmdArgs.existsArg("p", "print", "print-format") {
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
if cmdArgs.existsArg("c", "clean") {
|
||||
return syncClean(cmdArgs)
|
||||
}
|
||||
if cmdArgs.existsArg("l", "list") {
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
if cmdArgs.existsArg("g", "groups") {
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
if cmdArgs.existsArg("i", "info") {
|
||||
return syncInfo(targets)
|
||||
}
|
||||
if cmdArgs.existsArg("u", "sysupgrade") {
|
||||
return install(cmdArgs)
|
||||
}
|
||||
if len(cmdArgs.targets) > 0 {
|
||||
return install(cmdArgs)
|
||||
}
|
||||
if cmdArgs.existsArg("y", "refresh") {
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleRemove() (err error) {
|
||||
func handleRemove() error {
|
||||
removeVCSPackage(cmdArgs.targets)
|
||||
err = show(passToPacman(cmdArgs))
|
||||
return
|
||||
return show(passToPacman(cmdArgs))
|
||||
}
|
||||
|
||||
// NumberMenu presents a CLI for selecting packages to install.
|
||||
func numberMenu(pkgS []string) (err error) {
|
||||
var (
|
||||
aurErr, repoErr error
|
||||
aq aurQuery
|
||||
pq repoQuery
|
||||
lenaq, lenpq int
|
||||
)
|
||||
|
||||
pkgS = removeInvalidTargets(pkgS)
|
||||
var aurErr error
|
||||
var repoErr error
|
||||
var aq aurQuery
|
||||
var pq repoQuery
|
||||
var lenaq int
|
||||
var lenpq int
|
||||
|
||||
if mode == ModeAUR || mode == ModeAny {
|
||||
aq, aurErr = narrowSearch(pkgS, true)
|
||||
@ -492,12 +490,11 @@ func numberMenu(pkgS []string) (err error) {
|
||||
fmt.Print(bold(green(arrow + " ")))
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
numberBuf, overflow, err := reader.ReadLine()
|
||||
|
||||
numberBuf, overflow, err := reader.ReadLine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if overflow {
|
||||
return fmt.Errorf("Input too long")
|
||||
}
|
||||
@ -513,10 +510,7 @@ func numberMenu(pkgS []string) (err error) {
|
||||
target = i + 1
|
||||
}
|
||||
|
||||
if isInclude && include.get(target) {
|
||||
arguments.addTarget(pkg.DB().Name() + "/" + pkg.Name())
|
||||
}
|
||||
if !isInclude && !exclude.get(target) {
|
||||
if (isInclude && include.get(target)) || (!isInclude && !exclude.get(target)) {
|
||||
arguments.addTarget(pkg.DB().Name() + "/" + pkg.Name())
|
||||
}
|
||||
}
|
||||
@ -527,10 +521,7 @@ func numberMenu(pkgS []string) (err error) {
|
||||
target = i + 1 + len(pq)
|
||||
}
|
||||
|
||||
if isInclude && include.get(target) {
|
||||
arguments.addTarget("aur/" + pkg.Name)
|
||||
}
|
||||
if !isInclude && !exclude.get(target) {
|
||||
if (isInclude && include.get(target)) || (!isInclude && !exclude.get(target)) {
|
||||
arguments.addTarget("aur/" + pkg.Name)
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ var alpmConf alpm.PacmanConfig
|
||||
var alpmHandle *alpm.Handle
|
||||
|
||||
// Mode is used to restrict yay to AUR or repo only modes
|
||||
var mode targetMode = ModeAny
|
||||
var mode = ModeAny
|
||||
|
||||
func readAlpmConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
|
||||
file, err := os.Open(pacmanconf)
|
||||
|
154
main.go
154
main.go
@ -45,43 +45,43 @@ func setPaths() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func initConfig() (err error) {
|
||||
func initConfig() error {
|
||||
defaultSettings(&config)
|
||||
|
||||
if _, err = os.Stat(configFile); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(filepath.Dir(configFile), 0755)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Unable to create config directory:\n%s\n"+
|
||||
"The error was:\n%s", filepath.Dir(configFile), err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
// Save the default config if nothing is found
|
||||
config.saveConfig()
|
||||
} else {
|
||||
cfile, errf := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if errf != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cfile, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading config: %s\n", err)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
defer cfile.Close()
|
||||
|
||||
decoder := json.NewDecoder(cfile)
|
||||
err = decoder.Decode(&config)
|
||||
if err != nil {
|
||||
fmt.Println("Loading default Settings.\nError reading config:",
|
||||
err)
|
||||
if err := decoder.Decode(&config); err != nil {
|
||||
fmt.Println("Loading default Settings.\nError reading config:", err)
|
||||
defaultSettings(&config)
|
||||
return err
|
||||
}
|
||||
if _, err = os.Stat(config.BuildDir); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(config.BuildDir, 0755)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Unable to create BuildDir directory:\n%s\n"+
|
||||
|
||||
if _, err := os.Stat(config.BuildDir); os.IsNotExist(err) {
|
||||
if err = os.MkdirAll(config.BuildDir, 0755); err != nil {
|
||||
return fmt.Errorf("Unable to create BuildDir directory:\n%s\n"+
|
||||
"The error was:\n%s", config.BuildDir, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
func initVCS() (err error) {
|
||||
@ -92,22 +92,20 @@ func initVCS() (err error) {
|
||||
"The error was:\n%s", filepath.Dir(configFile), err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
vfile, err := os.OpenFile(vcsFile, os.O_RDONLY|os.O_CREATE, 0644)
|
||||
if err == nil {
|
||||
defer vfile.Close()
|
||||
decoder := json.NewDecoder(vfile)
|
||||
_ = decoder.Decode(&savedInfo)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
func initAlpm() (err error) {
|
||||
var value string
|
||||
var exists bool
|
||||
//var double bool
|
||||
|
||||
alpmConf, err = readAlpmConfig(config.PacmanConf)
|
||||
if err != nil {
|
||||
@ -171,93 +169,57 @@ func initAlpm() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func initAlpmHandle() (err error) {
|
||||
func initAlpmHandle() error {
|
||||
if alpmHandle != nil {
|
||||
err = alpmHandle.Release()
|
||||
if err != nil {
|
||||
if err := alpmHandle.Release(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
alpmHandle, err = alpmConf.CreateHandle()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Unable to CreateHandle: %s", err)
|
||||
return
|
||||
var err error
|
||||
if alpmHandle, err = alpmConf.CreateHandle(); err != nil {
|
||||
return fmt.Errorf("Unable to CreateHandle: %s", err)
|
||||
}
|
||||
|
||||
alpmHandle.SetQuestionCallback(questionCallback)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanup() {
|
||||
if alpmHandle != nil {
|
||||
temp := alpmHandle
|
||||
// set alpmHandle to nil to avoid entering this
|
||||
// branch of code again, at cleanup time.
|
||||
alpmHandle = nil
|
||||
must(temp.Release())
|
||||
}
|
||||
}
|
||||
|
||||
// must outputs the error if there is one,
|
||||
// then calls cleanup() and ends the program with exit code 1.
|
||||
// If err == nil, no action is taken.
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
cleanup()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
var status int
|
||||
var err error
|
||||
|
||||
if 0 == os.Geteuid() {
|
||||
if os.Geteuid() == 0 {
|
||||
fmt.Println("Please avoid running yay as root/sudo.")
|
||||
}
|
||||
|
||||
err = cmdArgs.parseCommandLine()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
status = 1
|
||||
goto cleanup
|
||||
}
|
||||
// Ensure release of alpmHandle
|
||||
defer cleanup()
|
||||
|
||||
err = setPaths()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
status = 1
|
||||
goto cleanup
|
||||
}
|
||||
|
||||
err = initConfig()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
status = 1
|
||||
goto cleanup
|
||||
}
|
||||
must(cmdArgs.parseCommandLine())
|
||||
must(setPaths())
|
||||
must(initConfig())
|
||||
|
||||
cmdArgs.extractYayOptions()
|
||||
|
||||
err = initVCS()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
status = 1
|
||||
goto cleanup
|
||||
|
||||
}
|
||||
|
||||
err = initAlpm()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
status = 1
|
||||
goto cleanup
|
||||
}
|
||||
|
||||
err = handleCmd()
|
||||
if err != nil {
|
||||
if err.Error() != "" {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
status = 1
|
||||
goto cleanup
|
||||
}
|
||||
|
||||
cleanup:
|
||||
//cleanup
|
||||
//from here on out don't exit if an error occurs
|
||||
//if we fail to save the configuration
|
||||
//at least continue on and try clean up other parts
|
||||
|
||||
if alpmHandle != nil {
|
||||
err = alpmHandle.Release()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
status = 1
|
||||
}
|
||||
}
|
||||
|
||||
os.Exit(status)
|
||||
must(initVCS())
|
||||
must(initAlpm())
|
||||
must(handleCmd())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user