File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/CosmicPredator/chibi/internal/ui"
7+ "github.com/CosmicPredator/chibi/internal/viewmodel"
8+ "github.com/spf13/cobra"
9+ )
10+
11+ func handleLogoutCommand (cmd * cobra.Command , args []string ) {
12+ err := viewmodel .HandleLogout ()
13+ if err != nil {
14+ fmt .Println (ui .ErrorText (err ))
15+ }
16+ }
17+
18+ var logoutCmd = & cobra.Command {
19+ Use : "logout" ,
20+ Short : "logs you out from anilist" ,
21+ Run : handleLogoutCommand ,
22+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ func Execute(version string) {
3030 rootCmd .CompletionOptions .DisableDefaultCmd = true
3131 rootCmd .AddCommand (
3232 loginCmd ,
33+ logoutCmd ,
3334 profileCmd ,
3435 mediaSearchCmd ,
3536 mediaListCmd ,
Original file line number Diff line number Diff line change 1+ package viewmodel
2+
3+ import (
4+ "fmt"
5+ "os"
6+ "path"
7+
8+ "github.com/CosmicPredator/chibi/internal/ui"
9+ )
10+
11+ // handler func to log user out from AniList
12+ // this is achieved by just deleting the config/chibi folder (for now)
13+
14+ // TODO: Implement proper logout operations
15+ func HandleLogout () error {
16+ osConfigPath , _ := os .UserConfigDir ()
17+ configDir := path .Join (osConfigPath , "chibi" )
18+
19+ _ , err := os .Stat (configDir )
20+ if err != nil {
21+ ui .HighlightedText ("Already logged out." )
22+ return nil
23+ }
24+
25+ err = os .RemoveAll (configDir )
26+ if err != nil {
27+ return err
28+ }
29+
30+ fmt .Println (ui .SuccessText ("Logged out successfully!" ))
31+ return nil
32+ }
You can’t perform that action at this time.
0 commit comments