mirror of
https://gitea.com/jolheiser/sip
synced 2024-11-22 19:51:58 +01:00
5b7b970a06
Signed-off-by: jolheiser <john.olheiser@gmail.com>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"gitea.com/jolheiser/beaver"
|
|
"gitea.com/jolheiser/tea/modules/config"
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var (
|
|
Logout = cli.Command{
|
|
Name: "logout",
|
|
Usage: "Log out of a Gitea server",
|
|
Action: doLogout,
|
|
}
|
|
)
|
|
|
|
func doLogout(ctx *cli.Context) error {
|
|
opts := make([]string, len(config.Logins))
|
|
for idx, login := range config.Logins {
|
|
opts[idx] = fmt.Sprintf("%s (%s)", login.Name, login.URL)
|
|
}
|
|
question := &survey.MultiSelect{
|
|
Message: "Which would you like to remove?",
|
|
Options: opts,
|
|
PageSize: 10,
|
|
}
|
|
answers := make([]string, 0)
|
|
|
|
if err := survey.AskOne(question, &answers); err != nil {
|
|
return err
|
|
}
|
|
|
|
idxs := make([]int, len(answers))
|
|
for idx, answer := range answers {
|
|
for idy, login := range config.Logins {
|
|
if answer == fmt.Sprintf("%s (%s)", login.Name, login.URL) {
|
|
idxs[len(answers)-idx-1] = idy
|
|
}
|
|
}
|
|
}
|
|
|
|
for _, idx := range idxs {
|
|
config.Logins = append(config.Logins[:idx], config.Logins[idx+1:]...)
|
|
}
|
|
|
|
if err := config.Save(); err != nil {
|
|
return err
|
|
}
|
|
|
|
beaver.Infof("Logged out of %d accounts! Remember to clean up your tokens!", len(answers))
|
|
|
|
return nil
|
|
}
|