mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
Merge pull request #909 from sosiska/patch-1
Some more code improvements
This commit is contained in:
commit
ec5746f09f
@ -288,8 +288,7 @@ func continueTask(s string, cont bool) bool {
|
||||
|
||||
fmt.Print(bold(green(arrow)+" "+s), bold(postFix))
|
||||
|
||||
len, err := fmt.Scanln(&response)
|
||||
if err != nil || len == 0 {
|
||||
if _, err := fmt.Scanln(&response); err != nil {
|
||||
return cont
|
||||
}
|
||||
|
||||
|
14
download.go
14
download.go
@ -164,15 +164,16 @@ func getPkgbuilds(pkgs []string) error {
|
||||
for _, base := range allBases {
|
||||
name := base.Pkgbase()
|
||||
_, err = os.Stat(filepath.Join(wd, name))
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
switch {
|
||||
case err != nil && !os.IsNotExist(err):
|
||||
fmt.Fprintln(os.Stderr, bold(red(smallArrow)), err)
|
||||
continue
|
||||
} else if os.IsNotExist(err) || cmdArgs.existsArg("f", "force") || shouldUseGit(filepath.Join(wd, name)) {
|
||||
case os.IsNotExist(err), cmdArgs.existsArg("f", "force"), shouldUseGit(filepath.Join(wd, name)):
|
||||
if err = os.RemoveAll(filepath.Join(wd, name)); err != nil {
|
||||
fmt.Fprintln(os.Stderr, bold(red(smallArrow)), err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
fmt.Printf("%s %s %s\n", yellow(smallArrow), cyan(name), "already downloaded -- use -f to overwrite")
|
||||
continue
|
||||
}
|
||||
@ -248,15 +249,16 @@ func getPkgbuildsfromABS(pkgs []string, path string) (bool, error) {
|
||||
}
|
||||
|
||||
_, err = os.Stat(filepath.Join(path, name))
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
switch {
|
||||
case err != nil && !os.IsNotExist(err):
|
||||
fmt.Fprintln(os.Stderr, bold(red(smallArrow)), err)
|
||||
continue
|
||||
} else if os.IsNotExist(err) || cmdArgs.existsArg("f", "force") {
|
||||
case os.IsNotExist(err), cmdArgs.existsArg("f", "force"):
|
||||
if err = os.RemoveAll(filepath.Join(path, name)); err != nil {
|
||||
fmt.Fprintln(os.Stderr, bold(red(smallArrow)), err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
fmt.Printf("%s %s %s\n", yellow(smallArrow), cyan(name), "already downloaded -- use -f to overwrite")
|
||||
continue
|
||||
}
|
||||
|
11
install.go
11
install.go
@ -134,7 +134,7 @@ func install(parser *arguments) error {
|
||||
return show(passToPacman(parser))
|
||||
}
|
||||
|
||||
if len(dp.Aur) > 0 && 0 == os.Geteuid() {
|
||||
if len(dp.Aur) > 0 && os.Geteuid() == 0 {
|
||||
return fmt.Errorf(bold(red(arrow)) + " Refusing to install AUR Packages as root, Aborting.")
|
||||
}
|
||||
|
||||
@ -165,12 +165,13 @@ func install(parser *arguments) error {
|
||||
fmt.Println()
|
||||
|
||||
if do.HasMake() {
|
||||
if config.RemoveMake == "yes" {
|
||||
switch config.RemoveMake {
|
||||
case "yes":
|
||||
removeMake = true
|
||||
} else if config.RemoveMake == "no" {
|
||||
case "no":
|
||||
removeMake = false
|
||||
} else if continueTask("Remove make dependencies after install?", false) {
|
||||
removeMake = true
|
||||
default:
|
||||
removeMake = continueTask("Remove make dependencies after install?", false)
|
||||
}
|
||||
}
|
||||
|
||||
|
24
parser.go
24
parser.go
@ -192,11 +192,12 @@ func (parser *arguments) addParam(option string, arg string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if parser.existsArg(option) {
|
||||
switch {
|
||||
case parser.existsArg(option):
|
||||
parser.doubles[option] = struct{}{}
|
||||
} else if isGlobal(option) {
|
||||
case isGlobal(option):
|
||||
parser.globals[option] = arg
|
||||
} else {
|
||||
default:
|
||||
parser.options[option] = arg
|
||||
}
|
||||
|
||||
@ -779,13 +780,13 @@ func (parser *arguments) parseLongOption(arg string, param string) (usedNext boo
|
||||
|
||||
arg = arg[2:]
|
||||
|
||||
split := strings.SplitN(arg, "=", 2)
|
||||
if len(split) == 2 {
|
||||
switch split := strings.SplitN(arg, "=", 2); {
|
||||
case len(split) == 2:
|
||||
err = parser.addParam(split[0], split[1])
|
||||
} else if hasParam(arg) {
|
||||
case hasParam(arg):
|
||||
err = parser.addParam(arg, param)
|
||||
usedNext = true
|
||||
} else {
|
||||
default:
|
||||
err = parser.addArg(arg)
|
||||
}
|
||||
|
||||
@ -822,13 +823,14 @@ func (parser *arguments) parseCommandLine() (err error) {
|
||||
nextArg = args[k+1]
|
||||
}
|
||||
|
||||
if parser.existsArg("--") {
|
||||
switch {
|
||||
case parser.existsArg("--"):
|
||||
parser.addTarget(arg)
|
||||
} else if strings.HasPrefix(arg, "--") {
|
||||
case strings.HasPrefix(arg, "--"):
|
||||
usedNext, err = parser.parseLongOption(arg, nextArg)
|
||||
} else if strings.HasPrefix(arg, "-") {
|
||||
case strings.HasPrefix(arg, "-"):
|
||||
usedNext, err = parser.parseShortOption(arg, nextArg)
|
||||
} else {
|
||||
default:
|
||||
parser.addTarget(arg)
|
||||
}
|
||||
|
||||
|
7
print.go
7
print.go
@ -219,7 +219,8 @@ func (do *depOrder) Print() {
|
||||
push := false
|
||||
pushMake := false
|
||||
|
||||
if len(base) > 1 || pkg != base[0].Name {
|
||||
switch {
|
||||
case len(base) > 1, pkg != base[0].Name:
|
||||
pkgStr += " ("
|
||||
pkgStrMake += " ("
|
||||
|
||||
@ -237,10 +238,10 @@ func (do *depOrder) Print() {
|
||||
|
||||
pkgStr = pkgStr[:len(pkgStr)-1] + ")"
|
||||
pkgStrMake = pkgStrMake[:len(pkgStrMake)-1] + ")"
|
||||
} else if do.Runtime.get(base[0].Name) {
|
||||
case do.Runtime.get(base[0].Name):
|
||||
aurLen++
|
||||
push = true
|
||||
} else {
|
||||
default:
|
||||
aurMakeLen++
|
||||
pushMake = true
|
||||
}
|
||||
|
10
query.go
10
query.go
@ -414,21 +414,21 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) {
|
||||
}
|
||||
|
||||
func lastBuildTime() (time.Time, error) {
|
||||
var time time.Time
|
||||
var lastTime time.Time
|
||||
|
||||
pkgs, _, _, _, err := filterPackages()
|
||||
if err != nil {
|
||||
return time, err
|
||||
return lastTime, err
|
||||
}
|
||||
|
||||
for _, pkg := range pkgs {
|
||||
thisTime := pkg.BuildDate()
|
||||
if thisTime.After(time) {
|
||||
time = thisTime
|
||||
if thisTime.After(lastTime) {
|
||||
lastTime = thisTime
|
||||
}
|
||||
}
|
||||
|
||||
return time, nil
|
||||
return lastTime, nil
|
||||
}
|
||||
|
||||
// Statistics returns statistics about packages installed in system
|
||||
|
Loading…
Reference in New Issue
Block a user