catch incompatible --clean flag when no operation is specified with better error message (#2644)

* improve error messaging when running yay -c

* use correct method in parsing -c flag

* better express prefixes in --help
This commit is contained in:
given
2025-07-18 08:04:28 -04:00
committed by GitHub
parent 5f4ad92263
commit fd62f7f4c8
3 changed files with 14 additions and 6 deletions

View File

@@ -52,7 +52,7 @@ func syncClean(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Argume
keepInstalled := false
keepCurrent := false
_, removeAll, _ := cmdArgs.GetArg("c", "clean")
removeAll := cmdArgs.ExistsArg("c", "clean")
for _, v := range run.PacmanConf.CleanMethod {
switch v {

8
cmd.go
View File

@@ -51,7 +51,7 @@ New operations:
yay {-Y --yay} [options] [package(s)]
If no operation is specified 'yay -Syu' will be performed
If no operation is specified and targets are provided -Y will be assumed
If no operation is specified and targets are provided, -Y will be assumed
New options:
-N --repo Assume targets are from the repositories
@@ -122,18 +122,18 @@ Permanent configuration options:
--timeupdate Check packages' AUR page for changes during sysupgrade
show specific options:
show specific options (used with -P):
-c --complete Used for completions
-d --defaultconfig Print default yay configuration
-g --currentconfig Print current yay configuration
-s --stats Display system package statistics
-w --news Print arch news
yay specific options:
yay specific options (used with -Y):
-c --clean Remove unneeded dependencies (-cc to ignore optdepends)
--gendb Generates development package DB used for updating
getpkgbuild specific options:
getpkgbuild specific options (used with -G):
-f --force Force download for existing ABS packages
-p --print Print pkgbuild of packages`)
}

View File

@@ -542,7 +542,7 @@ func hasParam(arg string) bool {
}
// Parses short hand options such as:
// -Syu -b/some/path -.
// -Syu -b /some/path -.
func (a *Arguments) parseShortOption(arg, param string) (usedNext bool, err error) {
if arg == "-" {
err = a.AddArg("-")
@@ -655,6 +655,14 @@ func (a *Arguments) Parse() error {
if len(a.Targets) > 0 {
a.Op = "Y"
} else {
// Handle args incompatible with -Syu
if a.ExistsArg("c", "clean") {
fmt.Println(gotext.Get("the clean command requires an operation to be specified"))
fmt.Println(gotext.Get("did you mean yay -Scc (clean caches) or yay -Ycc (clean orphaned packages)?"))
return errors.New(gotext.Get("invalid option"))
}
if _, err := a.parseShortOption("-Syu", ""); err != nil {
return err
}