mirror of
https://gitea.com/jolheiser/sip
synced 2024-11-26 07:33:48 +01:00
a60c71469d
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/sip/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
|
|
}
|