mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
refactor(main): move get cmds to their own file
This commit is contained in:
parent
2ed099a263
commit
65b1c4be69
4
cmd.go
4
cmd.go
@ -277,9 +277,7 @@ func handleGetpkgbuild(cmdArgs *settings.Arguments, dbExecutor db.Executor) erro
|
||||
if cmdArgs.ExistsArg("p", "print") {
|
||||
return printPkgbuilds(dbExecutor, config.Runtime.HTTPClient, cmdArgs.Targets)
|
||||
}
|
||||
return getPkgbuilds(dbExecutor,
|
||||
config.Runtime.CmdRunner, config.Runtime.CmdBuilder,
|
||||
cmdArgs.Targets, config.Runtime.Mode, config.AURURL, cmdArgs.ExistsArg("f", "force"))
|
||||
return getPkgbuilds(dbExecutor, config, cmdArgs.Targets, cmdArgs.ExistsArg("f", "force"))
|
||||
}
|
||||
|
||||
func handleYogurt(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
||||
|
37
download.go
37
download.go
@ -7,12 +7,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
"github.com/Jguer/yay/v10/pkg/download"
|
||||
"github.com/Jguer/yay/v10/pkg/settings"
|
||||
"github.com/Jguer/yay/v10/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v10/pkg/text"
|
||||
)
|
||||
|
||||
const gitDiffRefName = "AUR_SEEN"
|
||||
@ -115,34 +109,3 @@ func gitMerge(path, name string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPkgbuilds(dbExecutor db.Executor,
|
||||
cmdRunner exe.Runner,
|
||||
cmdBuilder exe.GitCmdBuilder, targets []string,
|
||||
mode settings.TargetMode,
|
||||
aurURL string,
|
||||
force bool) error {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cloned, errD := download.PKGBUILDRepos(dbExecutor, cmdRunner, cmdBuilder, targets, mode, aurURL, wd, force)
|
||||
if errD != nil {
|
||||
text.Errorln(errD)
|
||||
}
|
||||
|
||||
if len(targets) != len(cloned) {
|
||||
missing := []string{}
|
||||
for _, target := range targets {
|
||||
if _, ok := cloned[target]; !ok {
|
||||
missing = append(missing, target)
|
||||
}
|
||||
}
|
||||
text.Warnln(gotext.Get("Unable to find the following packages:"), strings.Join(missing, ", "))
|
||||
|
||||
err = fmt.Errorf("")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
72
get.go
Normal file
72
get.go
Normal file
@ -0,0 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
"github.com/Jguer/yay/v10/pkg/download"
|
||||
"github.com/Jguer/yay/v10/pkg/settings"
|
||||
"github.com/Jguer/yay/v10/pkg/text"
|
||||
)
|
||||
|
||||
// yay -Gp
|
||||
func printPkgbuilds(dbExecutor db.Executor, httpClient *http.Client, targets []string) error {
|
||||
pkgbuilds, err := download.GetPkgbuilds(dbExecutor, httpClient, targets, config.Runtime.Mode)
|
||||
if err != nil {
|
||||
text.Errorln(err)
|
||||
}
|
||||
|
||||
if len(pkgbuilds) != 0 {
|
||||
for target, pkgbuild := range pkgbuilds {
|
||||
fmt.Printf("\n\n# %s\n\n", target)
|
||||
fmt.Print(string(pkgbuild))
|
||||
}
|
||||
}
|
||||
|
||||
if len(pkgbuilds) != len(targets) {
|
||||
missing := []string{}
|
||||
for _, target := range targets {
|
||||
if _, ok := pkgbuilds[target]; !ok {
|
||||
missing = append(missing, target)
|
||||
}
|
||||
}
|
||||
text.Warnln(gotext.Get("Unable to find the following packages:"), strings.Join(missing, ", "))
|
||||
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// yay -G
|
||||
func getPkgbuilds(dbExecutor db.Executor, config *settings.Configuration, targets []string,
|
||||
force bool) error {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cloned, errD := download.PKGBUILDRepos(dbExecutor, config.Runtime.CmdRunner,
|
||||
config.Runtime.CmdBuilder, targets, config.Runtime.Mode, config.AURURL, wd, force)
|
||||
if errD != nil {
|
||||
text.Errorln(errD)
|
||||
}
|
||||
|
||||
if len(targets) != len(cloned) {
|
||||
missing := []string{}
|
||||
for _, target := range targets {
|
||||
if _, ok := cloned[target]; !ok {
|
||||
missing = append(missing, target)
|
||||
}
|
||||
}
|
||||
text.Warnln(gotext.Get("Unable to find the following packages:"), strings.Join(missing, ", "))
|
||||
|
||||
err = fmt.Errorf("")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
31
print.go
31
print.go
@ -2,16 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
aur "github.com/Jguer/aur"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
"github.com/Jguer/yay/v10/pkg/download"
|
||||
"github.com/Jguer/yay/v10/pkg/query"
|
||||
"github.com/Jguer/yay/v10/pkg/settings"
|
||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||
@ -270,31 +267,3 @@ outer:
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printPkgbuilds(dbExecutor db.Executor, httpClient *http.Client, targets []string) error {
|
||||
pkgbuilds, err := download.GetPkgbuilds(dbExecutor, httpClient, targets, config.Runtime.Mode)
|
||||
if err != nil {
|
||||
text.Errorln(err)
|
||||
}
|
||||
|
||||
if len(pkgbuilds) != 0 {
|
||||
for target, pkgbuild := range pkgbuilds {
|
||||
fmt.Printf("\n\n# %s\n\n", target)
|
||||
fmt.Print(string(pkgbuild))
|
||||
}
|
||||
}
|
||||
|
||||
if len(pkgbuilds) != len(targets) {
|
||||
missing := []string{}
|
||||
for _, target := range targets {
|
||||
if _, ok := pkgbuilds[target]; !ok {
|
||||
missing = append(missing, target)
|
||||
}
|
||||
}
|
||||
text.Warnln(gotext.Get("Unable to find the following packages:"), strings.Join(missing, ", "))
|
||||
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user