/
logout.go
42 lines (33 loc) · 934 Bytes
/
logout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package command
import (
client "github.com/ds3lab/easeml/client/go/easemlclient"
"fmt"
"github.com/spf13/viper"
"github.com/spf13/cobra"
)
// logoutCmd represents the logout command
var logoutCmd = &cobra.Command{
Use: "logout",
Short: "Logs the user out the ease.ml service.",
Long: ``,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
if apiKey == "" {
apiKey = viper.GetString("api-key")
}
serverAddress := viper.GetString("server-address")
context := client.Context{ServerAddress: serverAddress, UserCredentials: client.APIKeyCredentials{APIKey: apiKey}}
err := context.Logout()
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println("Logout successful.")
return
},
}
func init() {
rootCmd.AddCommand(logoutCmd)
logoutCmd.PersistentFlags().String("api-key", "", "API key of the user to log out.")
viper.BindPFlags(logoutCmd.PersistentFlags())
}