feat(yay): add boolean flags (#2285)

* feat(yay): add boolean flags

This feature now allows users to specify --<option>=<bool value> instead
of using --<option> and --no<option>. Specifying nothing results in the
boolean value being true. The flags prefixed with `no` are deprecated.

* chore(args): Print warning when using deprecated flags

* chore(yay): Update man page for deprecated options and add examples of
boolean flags being used
This commit is contained in:
Joey Holtzman 2023-09-27 03:36:57 -07:00 committed by GitHub
parent a1121556be
commit d368f99be0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 51 deletions

View File

@ -293,6 +293,9 @@ Unset the answer for the upgrade menu.
Show the clean menu. This menu gives you the chance to fully delete the Show the clean menu. This menu gives you the chance to fully delete the
downloaded build files from Yay's cache before redownloading a fresh copy. downloaded build files from Yay's cache before redownloading a fresh copy.
If 'cleanmenu' is enabled in the configuration file, you can temporarily disable it by
using '--cleanmenu=false' on the command line
.TP .TP
.B \-\-diffmenu .B \-\-diffmenu
Show the diff menu. This menu gives you the option to view diffs from Show the diff menu. This menu gives you the option to view diffs from
@ -311,15 +314,15 @@ before building.
recommended to edit pkgbuild variables unless you know what you are doing. recommended to edit pkgbuild variables unless you know what you are doing.
.TP .TP
.B \-\-nocleanmenu .B \-\-nocleanmenu *Deprecated*
Do not show the clean menu. Do not show the clean menu.
.TP .TP
.B \-\-nodiffmenu .B \-\-nodiffmenu *Deprecated*
Do not show the diff menu. Do not show the diff menu.
.TP .TP
.B \-\-noeditmenu .B \-\-noeditmenu *Deprecated*
Do not show the edit menu. Do not show the edit menu.
.TP .TP
@ -368,8 +371,11 @@ checked almost instantly and not require the original pkgbuild to be downloaded.
The slower pacaur-like devel checks can be implemented manually by piping The slower pacaur-like devel checks can be implemented manually by piping
a list of packages into yay (see \fBexamples\fR). a list of packages into yay (see \fBexamples\fR).
If 'devel' is enabled in the configuration file, you can temporarily disable it by
using '--devel=false' on the command line
.TP .TP
.B \-\-nodevel .B \-\-nodevel *Deprecated*
Do not check for development packages updates during sysupgrade. Do not check for development packages updates during sysupgrade.
.TP .TP
@ -381,7 +387,7 @@ This allows VCS packages to easily pull an update
instead of having to reclone the entire repo. instead of having to reclone the entire repo.
.TP .TP
.B \-\-nocleanafter .B \-\-nocleanafter *Deprecated*
Do not remove package sources after successful Install. Do not remove package sources after successful Install.
.TP .TP
@ -394,7 +400,7 @@ During sysupgrade also compare the build time of installed packages against
the last modification time of each package's AUR page. the last modification time of each package's AUR page.
.TP .TP
.B \-\-notimeupdate .B \-\-notimeupdate *Deprecated*
Do not consider build times during sysupgrade. Do not consider build times during sysupgrade.
.TP .TP
@ -402,7 +408,7 @@ Do not consider build times during sysupgrade.
Separate query results by source, AUR and sync Separate query results by source, AUR and sync
.TP .TP
.B \-\-noseparatesources .B \-\-noseparatesources *Deprecated*
Do not separate query results by source for searching Do not separate query results by source for searching
.TP .TP
@ -426,7 +432,7 @@ providers are found a menu will appear prompting you to pick one. This
increases dependency resolve time although this should not be noticeable. increases dependency resolve time although this should not be noticeable.
.TP .TP
.B \-\-noprovides .B \-\-noprovides *Deprecated*
Do not look for matching providers when searching for AUR packages. Do not look for matching providers when searching for AUR packages.
Yay will never show its provider menu but Pacman will still show its Yay will never show its provider menu but Pacman will still show its
provider menu for repo packages. provider menu for repo packages.
@ -437,7 +443,7 @@ Prompt to import unknown PGP keys from the \fBvalidpgpkeys\fR field of each
PKGBUILD. PKGBUILD.
.TP .TP
.B \-\-nopgpfetch .B \-\-nopgpfetch *Deprecated*
Do not prompt to import unknown PGP keys. This is likely to cause a build Do not prompt to import unknown PGP keys. This is likely to cause a build
failure unless using options such as \fB\-\-skippgpcheck\fR or a customized failure unless using options such as \fB\-\-skippgpcheck\fR or a customized
gpg config\%. gpg config\%.
@ -450,7 +456,7 @@ a conflict, causing a package to be removed without the user's confirmation.
However, this is very unlikely. However, this is very unlikely.
.TP .TP
.B \-\-nouseask .B \-\-nouseask *Deprecated*
Manually resolve package conflicts during the install. Packages which do not Manually resolve package conflicts during the install. Packages which do not
conflict will not need to be confined manually. conflict will not need to be confined manually.
@ -466,7 +472,7 @@ the user's responsibility to either resolve the reason Yay exited or run
a sysupgrade through pacman directly. a sysupgrade through pacman directly.
.TP .TP
.B \-\-nocombinedupgrade .B \-\-nocombinedupgrade *Deprecated*
During sysupgrade, Pacman \-Syu will be called, then the AUR upgrade will During sysupgrade, Pacman \-Syu will be called, then the AUR upgrade will
start. This means the upgrade menu and pkgbuild review will be performed start. This means the upgrade menu and pkgbuild review will be performed
after the sysupgrade has finished. after the sysupgrade has finished.
@ -479,7 +485,7 @@ are built or a package in the build queue is needed as a dependency to build
another package, install all the packages in the install queue. another package, install all the packages in the install queue.
.TP .TP
.B \-\-nobatchinstall .B \-\-nobatchinstall *Deprecated*
Always install AUR packages immediately after building them. Always install AUR packages immediately after building them.
.TP .TP
@ -536,7 +542,7 @@ Loop sudo calls in the background to prevent sudo from timing out during long
builds. builds.
.TP .TP
.B \-\-nosudoloop .B \-\-nosudoloop *Deprecated*
Do not loop sudo calls in the background. Do not loop sudo calls in the background.
.SH EXAMPLES .SH EXAMPLES

View File

@ -81,7 +81,7 @@ func main() {
cmdArgs := parser.MakeArguments() cmdArgs := parser.MakeArguments()
// Parse command line // Parse command line
if err = cfg.ParseCommandLine(cmdArgs); err != nil { if err = cfg.ParseCommandLine(cmdArgs, fallbackLog); err != nil {
if str := err.Error(); str != "" { if str := err.Error(); str != "" {
fallbackLog.Errorln(str) fallbackLog.Errorln(str)
} }

View File

@ -25,7 +25,7 @@ func handleCmd(logger *text.Logger) error {
} }
cmdArgs := parser.MakeArguments() cmdArgs := parser.MakeArguments()
if errP := cfg.ParseCommandLine(cmdArgs); errP != nil { if errP := cfg.ParseCommandLine(cmdArgs, logger); errP != nil {
return errP return errP
} }

View File

@ -5,21 +5,24 @@ import (
"strings" "strings"
"github.com/Jguer/yay/v12/pkg/settings/parser" "github.com/Jguer/yay/v12/pkg/settings/parser"
"github.com/Jguer/yay/v12/pkg/text"
"github.com/leonelquinteros/gotext"
) )
func (c *Configuration) ParseCommandLine(a *parser.Arguments) error { func (c *Configuration) ParseCommandLine(a *parser.Arguments, logger *text.Logger) error {
if err := a.Parse(); err != nil { if err := a.Parse(); err != nil {
return err return err
} }
c.extractYayOptions(a) c.extractYayOptions(a, logger)
return nil return nil
} }
func (c *Configuration) extractYayOptions(a *parser.Arguments) { func (c *Configuration) extractYayOptions(a *parser.Arguments, logger *text.Logger) {
for option, value := range a.Options { for option, value := range a.Options {
if c.handleOption(option, value.First()) { if c.handleOption(option, value.First(), logger) {
a.DelArg(option) a.DelArg(option)
} }
} }
@ -41,31 +44,39 @@ func (c *Configuration) extractYayOptions(a *parser.Arguments) {
} }
} }
func (c *Configuration) handleOption(option, value string) bool { func (c *Configuration) handleOption(option, value string, logger *text.Logger) bool {
boolValue, err := strconv.ParseBool(value)
if err != nil {
boolValue = true
}
switch option { switch option {
case "aururl": case "aururl":
c.AURURL = value c.AURURL = value
case "aurrpcurl": case "aurrpcurl":
c.AURRPCURL = value c.AURRPCURL = value
case "save": case "save":
c.SaveConfig = true c.SaveConfig = boolValue
case "afterclean", "cleanafter": case "afterclean", "cleanafter":
c.CleanAfter = true c.CleanAfter = boolValue
case "noafterclean", "nocleanafter": case "noafterclean", "nocleanafter":
c.CleanAfter = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--cleanafter=false' instead", option))
c.CleanAfter = !boolValue
case "keepsrc": case "keepsrc":
c.KeepSrc = true c.KeepSrc = boolValue
case "debug": case "debug":
c.Debug = true c.Debug = boolValue
return false return !boolValue
case "devel": case "devel":
c.Devel = true c.Devel = boolValue
case "nodevel": case "nodevel":
c.Devel = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--devel=false' instead", option))
c.Devel = !boolValue
case "timeupdate": case "timeupdate":
c.TimeUpdate = true c.TimeUpdate = boolValue
case "notimeupdate": case "notimeupdate":
c.TimeUpdate = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--timeupdate=false' instead", option))
c.TimeUpdate = !boolValue
case "topdown": case "topdown":
c.BottomUp = false c.BottomUp = false
case "bottomup": case "bottomup":
@ -84,7 +95,7 @@ func (c *Configuration) handleOption(option, value string) bool {
case "searchby": case "searchby":
c.SearchBy = value c.SearchBy = value
case "noconfirm": case "noconfirm":
NoConfirm = true NoConfirm = boolValue
case "config": case "config":
c.PacmanConf = value c.PacmanConf = value
case "redownload": case "redownload":
@ -102,9 +113,10 @@ func (c *Configuration) handleOption(option, value string) bool {
case "norebuild": case "norebuild":
c.ReBuild = parser.RebuildModeNo c.ReBuild = parser.RebuildModeNo
case "batchinstall": case "batchinstall":
c.BatchInstall = true c.BatchInstall = boolValue
case "nobatchinstall": case "nobatchinstall":
c.BatchInstall = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--batchinstall=false' instead", option))
c.BatchInstall = !boolValue
case "answerclean": case "answerclean":
c.AnswerClean = value c.AnswerClean = value
case "noanswerclean": case "noanswerclean":
@ -155,37 +167,45 @@ func (c *Configuration) handleOption(option, value string) bool {
c.RequestSplitN = n c.RequestSplitN = n
} }
case "sudoloop": case "sudoloop":
c.SudoLoop = true c.SudoLoop = boolValue
case "nosudoloop": case "nosudoloop":
c.SudoLoop = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--sudoloop=false' instead", option))
c.SudoLoop = !boolValue
case "provides": case "provides":
c.Provides = true c.Provides = boolValue
case "noprovides": case "noprovides":
c.Provides = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--provides=false' instead", option))
c.Provides = !boolValue
case "pgpfetch": case "pgpfetch":
c.PGPFetch = true c.PGPFetch = boolValue
case "nopgpfetch": case "nopgpfetch":
c.PGPFetch = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--pgpfetch=false' instead", option))
c.PGPFetch = !boolValue
case "cleanmenu": case "cleanmenu":
c.CleanMenu = true c.CleanMenu = boolValue
case "nocleanmenu": case "nocleanmenu":
c.CleanMenu = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--cleanmenu=false' instead", option))
c.CleanMenu = !boolValue
case "diffmenu": case "diffmenu":
c.DiffMenu = true c.DiffMenu = boolValue
case "nodiffmenu": case "nodiffmenu":
c.DiffMenu = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--diffmenu=false' instead", option))
c.DiffMenu = !boolValue
case "editmenu": case "editmenu":
c.EditMenu = true c.EditMenu = boolValue
case "noeditmenu": case "noeditmenu":
c.EditMenu = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--editmenu=false' instead", option))
c.EditMenu = !boolValue
case "useask": case "useask":
c.UseAsk = true c.UseAsk = boolValue
case "nouseask": case "nouseask":
c.UseAsk = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--useask=false' instead", option))
c.UseAsk = !boolValue
case "combinedupgrade": case "combinedupgrade":
c.CombinedUpgrade = true c.CombinedUpgrade = boolValue
case "nocombinedupgrade": case "nocombinedupgrade":
c.CombinedUpgrade = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--combinedupgrade=false' instead", option))
c.CombinedUpgrade = !boolValue
case "a", "aur": case "a", "aur":
c.Mode = parser.ModeAUR c.Mode = parser.ModeAUR
case "repo": case "repo":
@ -199,9 +219,10 @@ func (c *Configuration) handleOption(option, value string) bool {
case "askyesremovemake": case "askyesremovemake":
c.RemoveMake = "askyes" c.RemoveMake = "askyes"
case "separatesources": case "separatesources":
c.SeparateSources = true c.SeparateSources = boolValue
case "noseparatesources": case "noseparatesources":
c.SeparateSources = false logger.Warnln(gotext.Get("'--%s' is deprecated. Use '--separatesources=false' instead", option))
c.SeparateSources = !boolValue
default: default:
return false return false
} }