mirror of
https://github.com/Jguer/yay
synced 2024-09-01 06:08:39 +00:00
New print option, added new completion syntax, fixed fish completion
This commit is contained in:
parent
14f83053a5
commit
42889821d3
74
cmd.go
74
cmd.go
|
@ -5,13 +5,11 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var cmdArgs = makeArguments()
|
||||
|
@ -291,6 +289,8 @@ func handleCmd() (changedConfig bool, err error) {
|
|||
passToPacman(cmdArgs)
|
||||
case "G", "getpkgbuild":
|
||||
err = handleGetpkgbuild()
|
||||
case "P", "print":
|
||||
err = handlePrint()
|
||||
case "Y", "--yay":
|
||||
err = handleYay()
|
||||
default:
|
||||
|
@ -314,9 +314,6 @@ func handleConfig(option string) (changedConfig bool) {
|
|||
config.CleanAfter = true
|
||||
case "noafterclean":
|
||||
config.CleanAfter = false
|
||||
// case "printconfig":
|
||||
// fmt.Printf("%#v", config)
|
||||
// os.Exit(0)
|
||||
// case "gendb":
|
||||
// err = createDevelDB()
|
||||
// if err != nil {
|
||||
|
@ -339,14 +336,6 @@ func handleConfig(option string) (changedConfig bool) {
|
|||
config.SortMode = TopDown
|
||||
case "--bottomup":
|
||||
config.SortMode = BottomUp
|
||||
// case "complete":
|
||||
// config.Shell = "sh"
|
||||
// complete()
|
||||
// os.Exit(0)
|
||||
// case "fcomplete":
|
||||
// config.Shell = fishShell
|
||||
// complete()
|
||||
// os.Exit(0)
|
||||
// case "help":
|
||||
// usage()
|
||||
// os.Exit(0)
|
||||
|
@ -367,12 +356,31 @@ func handleVersion() {
|
|||
fmt.Printf("yay v%s\n", version)
|
||||
}
|
||||
|
||||
func handlePrint() (err error) {
|
||||
switch {
|
||||
case cmdArgs.existsArg("d", "defaultconfig"):
|
||||
fmt.Printf("%#v", config)
|
||||
case cmdArgs.existsArg("n", "numberupgrades"):
|
||||
case cmdArgs.existsArg("u", "upgrades"):
|
||||
case cmdArgs.existsArg("c", "complete"):
|
||||
switch {
|
||||
case cmdArgs.existsArg("f", "fish"):
|
||||
complete("fish")
|
||||
default:
|
||||
complete("sh")
|
||||
}
|
||||
case cmdArgs.existsArg("d", "defaultconfig"):
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleYay() (err error) {
|
||||
//_, options, targets := cmdArgs.formatArgs()
|
||||
if cmdArgs.existsArg("h", "help") {
|
||||
usage()
|
||||
} else if cmdArgs.existsArg("printconfig") {
|
||||
fmt.Printf("%#v", config)
|
||||
} else if cmdArgs.existsArg("gendb") {
|
||||
err = createDevelDB()
|
||||
if err != nil {
|
||||
|
@ -382,12 +390,6 @@ func handleYay() (err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else if cmdArgs.existsArg("complete") {
|
||||
config.Shell = "sh"
|
||||
complete()
|
||||
} else if cmdArgs.existsArg("fcomplete") {
|
||||
config.Shell = "fish"
|
||||
complete()
|
||||
} else if cmdArgs.existsArg("stats") {
|
||||
err = localStatistics()
|
||||
} else if cmdArgs.existsArg("cleandeps") {
|
||||
|
@ -640,36 +642,6 @@ func numberMenu(pkgS []string, flags []string) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
// Complete provides completion info for shells
|
||||
func complete() error {
|
||||
path := completionFile + config.Shell + ".cache"
|
||||
info, err := os.Stat(path)
|
||||
if os.IsNotExist(err) || time.Since(info.ModTime()).Hours() > 48 {
|
||||
os.MkdirAll(filepath.Dir(completionFile), 0755)
|
||||
out, errf := os.Create(path)
|
||||
if errf != nil {
|
||||
return errf
|
||||
}
|
||||
|
||||
if createAURList(out) != nil {
|
||||
defer os.Remove(path)
|
||||
}
|
||||
erra := createRepoList(out)
|
||||
|
||||
out.Close()
|
||||
return erra
|
||||
}
|
||||
|
||||
in, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
_, err = io.Copy(os.Stdout, in)
|
||||
return err
|
||||
}
|
||||
|
||||
// passToPacman outsorces execution to pacman binary without modifications.
|
||||
func passToPacman(args *arguments) error {
|
||||
var cmd *exec.Cmd
|
||||
|
|
|
@ -3,16 +3,17 @@ package main
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
alpm "github.com/jguer/go-alpm"
|
||||
)
|
||||
|
||||
const fishShell = "fish"
|
||||
|
||||
//CreateAURList creates a new completion file
|
||||
func createAURList(out *os.File) (err error) {
|
||||
func createAURList(out *os.File, shell string) (err error) {
|
||||
resp, err := http.Get("https://aur.archlinux.org/packages.gz")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -25,7 +26,7 @@ func createAURList(out *os.File) (err error) {
|
|||
for scanner.Scan() {
|
||||
fmt.Print(scanner.Text())
|
||||
out.WriteString(scanner.Text())
|
||||
if config.Shell == fishShell {
|
||||
if shell == "fish" {
|
||||
fmt.Print("\tAUR\n")
|
||||
out.WriteString("\tAUR\n")
|
||||
} else {
|
||||
|
@ -38,7 +39,7 @@ func createAURList(out *os.File) (err error) {
|
|||
}
|
||||
|
||||
//CreatePackageList appends Repo packages to completion cache
|
||||
func createRepoList(out *os.File) (err error) {
|
||||
func createRepoList(out *os.File, shell string) (err error) {
|
||||
dbList, err := alpmHandle.SyncDbs()
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -48,7 +49,7 @@ func createRepoList(out *os.File) (err error) {
|
|||
_ = db.PkgCache().ForEach(func(pkg alpm.Package) error {
|
||||
fmt.Print(pkg.Name())
|
||||
out.WriteString(pkg.Name())
|
||||
if config.Shell == fishShell {
|
||||
if shell == "fish" {
|
||||
fmt.Print("\t" + pkg.DB().Name() + "\n")
|
||||
out.WriteString("\t" + pkg.DB().Name() + "\n")
|
||||
} else {
|
||||
|
@ -61,3 +62,40 @@ func createRepoList(out *os.File) (err error) {
|
|||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// Complete provides completion info for shells
|
||||
func complete(shell string) error {
|
||||
var path string
|
||||
|
||||
if shell == "fish" {
|
||||
path = completionFile + "fish" + ".cache"
|
||||
} else {
|
||||
path = completionFile + "sh" + ".cache"
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
|
||||
if os.IsNotExist(err) || time.Since(info.ModTime()).Hours() > 48 {
|
||||
os.MkdirAll(filepath.Dir(completionFile), 0755)
|
||||
out, errf := os.Create(path)
|
||||
if errf != nil {
|
||||
return errf
|
||||
}
|
||||
|
||||
if createAURList(out, shell) != nil {
|
||||
defer os.Remove(path)
|
||||
}
|
||||
erra := createRepoList(out, shell)
|
||||
|
||||
out.Close()
|
||||
return erra
|
||||
}
|
||||
|
||||
in, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
_, err = io.Copy(os.Stdout, in)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ type Configuration struct {
|
|||
BuildDir string `json:"buildDir"`
|
||||
Editor string `json:"editor"`
|
||||
MakepkgBin string `json:"makepkgbin"`
|
||||
Shell string `json:"-"`
|
||||
PacmanBin string `json:"pacmanbin"`
|
||||
PacmanConf string `json:"pacmanconf"`
|
||||
TarBin string `json:"tarbin"`
|
||||
|
|
|
@ -132,6 +132,8 @@ func (parser *arguments) needRoot() bool {
|
|||
//yay specific
|
||||
case "Y", "yay":
|
||||
return false
|
||||
case "P", "print":
|
||||
return false
|
||||
case "G", "getpkgbuild":
|
||||
return false
|
||||
default:
|
||||
|
@ -315,6 +317,8 @@ func isOp(op string) bool {
|
|||
//yay specific
|
||||
case "Y", "yay":
|
||||
return true
|
||||
case "P", "print":
|
||||
return true
|
||||
case "G", "getpkgbuild":
|
||||
return true
|
||||
default:
|
||||
|
|
5
yay.fish
5
yay.fish
|
@ -5,18 +5,20 @@ set -l progname yay
|
|||
|
||||
set -l listinstalled "(pacman -Q | string replace ' ' \t)"
|
||||
# This might be an issue if another package manager is also installed (e.g. for containers)
|
||||
set -l listall "(yay --fcomplete)"
|
||||
set -l listall "(yay -Pcf)"
|
||||
set -l listrepos "(__fish_print_pacman_repos)"
|
||||
set -l listgroups "(pacman -Sg)\t'Package Group'"
|
||||
set -l listpacman "(__fish_print_packages)"
|
||||
set -l noopt 'not __fish_contains_opt -s S -s D -s Q -s R -s U -s T -s F database query sync remove upgrade deptest files'
|
||||
set -l database '__fish_contains_opt -s D database'
|
||||
set -l getpkgbuild '__fish_contains_opt -s G getpkgbuild'
|
||||
set -l print '__fish_contains_opt -s P print'
|
||||
set -l query '__fish_contains_opt -s Q query'
|
||||
set -l remove '__fish_contains_opt -s R remove'
|
||||
set -l sync '__fish_contains_opt -s S sync'
|
||||
set -l upgrade '__fish_contains_opt -s U upgrade'
|
||||
set -l files '__fish_contains_opt -s F files'
|
||||
set -l yayspecific '__fish_contains_opt -s Y yay'
|
||||
|
||||
complete -c pacman -e
|
||||
complete -c pacman -f
|
||||
|
@ -28,6 +30,7 @@ complete -c $progname -n $noopt -a "-Q" -d "Query the package database"
|
|||
complete -c $progname -s D -f -l database -n $noopt -d 'Modify the package database'
|
||||
complete -c $progname -s Q -f -l query -n $noopt -d 'Query the package database'
|
||||
complete -c $progname -s G -f -l getpkgbuild -n $noopt -d 'Get PKGBUILD from ABS or AUR'
|
||||
complete -c $progname -s P -f -l print -n $noopt -d 'Print information'
|
||||
complete -c $progname -s R -f -l remove -n $noopt -d 'Remove packages from the system'
|
||||
complete -c $progname -s S -f -l sync -n $noopt -d 'Synchronize packages'
|
||||
complete -c $progname -s T -f -l deptest -n $noopt -d 'Check if dependencies are installed'
|
||||
|
|
Loading…
Reference in a new issue