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

@@ -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
}