forked from Jguer/yay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental vote util to yay (Jguer#1765)
* feat(vote): add vote utility * update deps * add vote and unvote capabilities * use -W for web ops * add fish completions * add bash completion * add zsh completion * add md instructions
- Loading branch information
Showing
12 changed files
with
152 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/Jguer/aur" | ||
"github.com/Jguer/votar/pkg/vote" | ||
"github.com/leonelquinteros/gotext" | ||
|
||
"github.com/Jguer/yay/v11/pkg/query" | ||
) | ||
|
||
type ErrAURVote struct { | ||
inner error | ||
pkgName string | ||
} | ||
|
||
func (e *ErrAURVote) Error() string { | ||
return gotext.Get("Unable to handle package vote for: %s. err: %s", e.pkgName, e.inner.Error()) | ||
} | ||
|
||
func handlePackageVote(ctx context.Context, | ||
targets []string, aurClient *aur.Client, | ||
voteClient *vote.Client, splitN int, upvote bool, | ||
) error { | ||
infos, err := query.AURInfoPrint(ctx, aurClient, targets, splitN) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(infos) == 0 { | ||
fmt.Println(gotext.Get(" there is nothing to do")) | ||
return nil | ||
} | ||
|
||
for _, info := range infos { | ||
var err error | ||
if upvote { | ||
err = voteClient.Vote(ctx, info.PackageBase) | ||
} else { | ||
err = voteClient.Unvote(ctx, info.PackageBase) | ||
} | ||
|
||
if err != nil { | ||
if errors.Is(err, vote.ErrNoCredentials) { | ||
return errors.New( | ||
gotext.Get("%s: please set AUR_USERNAME and AUR_PASSWORD environment variables for voting", | ||
err.Error())) | ||
} | ||
|
||
return &ErrAURVote{inner: err, pkgName: info.Name} | ||
} | ||
} | ||
|
||
return nil | ||
} |