Skip to content

Commit

Permalink
refactor(main): move get cmds to their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Aug 5, 2021
1 parent 2ed099a commit 65b1c4b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 71 deletions.
4 changes: 1 addition & 3 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 0 additions & 37 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 changes: 72 additions & 0 deletions get.go
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 31 deletions print.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 65b1c4b

Please sign in to comment.