Skip to content

Commit

Permalink
feat: add logout subcommand for jira
Browse files Browse the repository at this point in the history
  • Loading branch information
HandOfGod94 committed Nov 12, 2023
1 parent f0fd4fa commit 0b0b408
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/fatih/color"
config "github.com/handofgod94/gh-jira-changelog/pkg/jira_changelog/jira/config_service"
"github.com/handofgod94/gh-jira-changelog/pkg/jira_changelog/jira/oauth"
"github.com/spf13/cobra"
)
Expand All @@ -27,7 +28,12 @@ var authCmd = &cobra.Command{

fmt.Println(color.GreenString("Login successful"))
case "logout":
panic("To be implemented")
err := config.Clear()
if err != nil {
return err
}
fmt.Print(color.CyanString("Logged out successfully."))
return nil
default:
return fmt.Errorf("invalid argument %s", args[0])
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/jira_changelog/jira/config_service/config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path"

"github.com/mitchellh/go-homedir"
"golang.org/x/exp/slog"
)

func Save(v any, filepath string) error {
Expand Down Expand Up @@ -53,6 +54,22 @@ func Load(v any, filepath string) (err error) {
return nil
}

func Clear() error {
confdir, err := defaultConfDir()
if err != nil {
return err
}

slog.Info("clearing config dir", "Dir", confdir)

if err := os.RemoveAll(confdir); err != nil {
slog.Error("failed to delete conf dir", "error", err)
return err
}

return nil
}

func defaultConfDir() (res string, err error) {
filepath := path.Join("gh-jira-changelog")
res = os.Getenv("XDG_CONFIG_HOME")
Expand Down

0 comments on commit 0b0b408

Please sign in to comment.