-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5b37c0
commit e7d1ebc
Showing
6 changed files
with
71 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package reset | ||
|
||
const ( | ||
ERRORLOGOUT = "Failed to log out during reset process: %s. Check your settings and try again. If the error persists, please contact Azion support." | ||
) |
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,9 @@ | ||
package reset | ||
|
||
const ( | ||
USAGE = "reset" | ||
SHORTDESCRIPTION = "Resets settings to default" | ||
LONGDESCRIPTION = "Resets your settings to default and deletes personal token if possible" | ||
FLAGHELP = "Displays more information about the reset command" | ||
SUCCESS = "Sucessfully reseted to default settings" | ||
) |
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,52 @@ | ||
package reset | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
msg "github.com/aziontech/azion-cli/messages/reset" | ||
api "github.com/aziontech/azion-cli/pkg/api/personal_token" | ||
"github.com/aziontech/azion-cli/pkg/cmdutil" | ||
"github.com/aziontech/azion-cli/pkg/logger" | ||
"github.com/aziontech/azion-cli/pkg/token" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmd(f *cmdutil.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: msg.USAGE, | ||
Short: msg.SHORTDESCRIPTION, | ||
Long: msg.LONGDESCRIPTION, | ||
Example: heredoc.Doc(` | ||
$ azion logout --help | ||
`), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
settings, err := token.ReadSettings() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if settings.UUID != "" { | ||
client := api.NewClient(f.HttpClient, f.Config.GetString("api_url"), f.Config.GetString("token")) | ||
err = client.Delete(context.Background(), settings.UUID) | ||
if err != nil { | ||
return fmt.Errorf(msg.ERRORLOGOUT, err.Error()) | ||
} | ||
} | ||
|
||
settings = token.Settings{} | ||
err = token.WriteSettings(settings) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logger.LogSuccessBye(f.IOStreams.Out, msg.SUCCESS) | ||
return nil | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.BoolP("help", "h", false, msg.FLAGHELP) | ||
return cmd | ||
} |
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