Skip to content

Commit

Permalink
add option/setting "AurRpcUrl" (#1809)
Browse files Browse the repository at this point in the history
Signed-off-by: moson-mo <mo-son@mailbox.org>
  • Loading branch information
moson-mo committed Sep 18, 2022
1 parent 7f9ac34 commit 647d160
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Permanent configuration options:
config file when used
--aururl <url> Set an alternative AUR URL
--aurrpcurl <url> Set an alternative URL for the AUR /rpc endpoint
--builddir <dir> Directory used to download and run PKGBUILDS
--editor <file> Editor to use when editing PKGBUILDs
--editorflags <flags> Pass arguments to editor
Expand Down
2 changes: 1 addition & 1 deletion completions/bash
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ _yay() {
noansweredit noanswerupgrade cleanmenu diffmenu editmenu upgrademenu cleanafter nocleanafter
nocleanmenu nodiffmenu noupgrademenu provides noprovides pgpfetch nopgpfetch
useask nouseask combinedupgrade nocombinedupgrade aur repo makepkgconf
nomakepkgconf askremovemake removemake noremovemake completioninterval aururl
nomakepkgconf askremovemake removemake noremovemake completioninterval aururl aurrpcurl
searchby batchinstall nobatchinstall'
'b d h q r v')
yays=('clean gendb' 'c')
Expand Down
1 change: 1 addition & 0 deletions completions/fish
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ complete -c $progname -n "$getpkgbuild" -s p -l print -d 'Print pkgbuild of pack
# Permanent configuration settings
complete -c $progname -n "not $noopt" -l save -d 'Save current arguments to yay permanent configuration' -f
complete -c $progname -n "not $noopt" -l aururl -d 'Set an alternative AUR URL' -f
complete -c $progname -n "not $noopt" -l aurrpcurl -d 'Set an alternative URL for the AUR /rpc endpoint' -f
complete -c $progname -n "not $noopt" -l builddir -d 'Directory to use for Building AUR Packages' -r
complete -c $progname -n "not $noopt" -l editor -d 'Editor to use' -f
complete -c $progname -n "not $noopt" -l editorflags -d 'Editor flags to use' -f
Expand Down
1 change: 1 addition & 0 deletions completions/zsh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ _pacman_opts_common=(
'--repo[Assume targets are from the repositories]'
{-a,--aur}'[Assume targets are from the AUR]'
'--aururl[Set an alternative AUR URL]:url'
'--aurrpcurl[Set an alternative URL for the AUR /rpc endpoint]:url'
'--arch[Set an alternate architecture]'
{-b,--dbpath}'[Alternate database location]:database_location:_files -/'
'--color[colorize the output]:color options:(always never auto)'
Expand Down
4 changes: 4 additions & 0 deletions doc/yay.8
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ file.
.B \-\-aururl
Set an alternative AUR URL.

.TP
.B \-\-aurrpcurl
Set an alternative URL for the AUR /rpc endpoint.

.TP
.B \-\-builddir <dir>
Directory to use for Building AUR Packages. This directory is also used as
Expand Down
17 changes: 16 additions & 1 deletion pkg/settings/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,29 @@ func (c *Configuration) extractYayOptions(a *parser.Arguments) {
}
}

c.Runtime.AURClient.BaseURL = strings.TrimRight(c.AURURL, "/") + "/rpc?"
c.AURURL = strings.TrimRight(c.AURURL, "/")
c.Runtime.AURClient.BaseURL = c.AURURL + "/rpc?"

// if AurRPCURL is set, use that for /rpc calls
if c.AURRPCURL != "" {
if !strings.HasSuffix(c.AURRPCURL, "?") {
if strings.HasSuffix(c.AURRPCURL, "/rpc") {
c.AURRPCURL += "?"
} else {
c.AURRPCURL = strings.TrimRight(c.AURRPCURL, "/") + "/rpc?"
}
}

c.Runtime.AURClient.BaseURL = c.AURRPCURL
}
}

func (c *Configuration) handleOption(option, value string) bool {
switch option {
case "aururl":
c.AURURL = value
case "aurrpcurl":
c.AURRPCURL = value
case "save":
c.Runtime.SaveConfig = true
case "afterclean", "cleanafter":
Expand Down
2 changes: 2 additions & 0 deletions pkg/settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var NoConfirm = false
// Configuration stores yay's config.
type Configuration struct {
AURURL string `json:"aururl"`
AURRPCURL string `json:"aurrpcurl"`
BuildDir string `json:"buildDir"`
Editor string `json:"editor"`
EditorFlags string `json:"editorflags"`
Expand Down Expand Up @@ -110,6 +111,7 @@ func (c *Configuration) Save(configPath string) error {

func (c *Configuration) expandEnv() {
c.AURURL = os.ExpandEnv(c.AURURL)
c.AURRPCURL = os.ExpandEnv(c.AURRPCURL)
c.BuildDir = os.ExpandEnv(c.BuildDir)
c.Editor = os.ExpandEnv(c.Editor)
c.EditorFlags = os.ExpandEnv(c.EditorFlags)
Expand Down
2 changes: 2 additions & 0 deletions pkg/settings/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ func isArg(arg string) bool {
case "machinereadable":
// yay options
case "aururl":
case "aurrpcurl":
case "save":
case "afterclean", "cleanafter":
case "noafterclean", "nocleanafter":
Expand Down Expand Up @@ -520,6 +521,7 @@ func hasParam(arg string) bool {
case "color":
// yay params
case "aururl":
case "aurrpcurl":
case "mflags":
case "gpgflags":
case "gitflags":
Expand Down

0 comments on commit 647d160

Please sign in to comment.