Skip to content

Commit a430791

Browse files
committed
Added 'scw logout' command
1 parent ec8c96b commit a430791

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

cli.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ var commands = []*Command{
164164
cmdInspect,
165165
cmdKill,
166166
cmdLogin,
167+
cmdLogout,
167168
cmdLogs,
168169
cmdPatch,
169170
cmdPort,
@@ -220,6 +221,7 @@ func main() {
220221
usage()
221222
}
222223
name := args[0]
224+
223225
args = args[1:]
224226

225227
for _, cmd := range commands {

logout.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
log "github.com/Sirupsen/logrus"
7+
)
8+
9+
var cmdLogout = &Command{
10+
Exec: runLogout,
11+
UsageLine: "logout [OPTIONS]",
12+
Description: "Log out from the Scaleway API",
13+
Help: "Log out from the Scaleway API.",
14+
}
15+
16+
func init() {
17+
cmdLogout.Flag.BoolVar(&logoutHelp, []string{"h", "-help"}, false, "Print usage")
18+
}
19+
20+
// FLags
21+
var logoutHelp bool // -h, --help flag
22+
23+
func runLogout(cmd *Command, args []string) {
24+
if logoutHelp {
25+
cmd.PrintUsage()
26+
}
27+
if len(args) != 0 {
28+
cmd.PrintShortUsage()
29+
}
30+
31+
scwrcPath, err := GetConfigFilePath()
32+
if err != nil {
33+
log.Fatalf("Unable to get scwrc config file path: %v", err)
34+
}
35+
36+
if _, err = os.Stat(scwrcPath); err == nil {
37+
err = os.Remove(scwrcPath)
38+
if err != nil {
39+
log.Fatalf("Unable to remove scwrc config file: %v", err)
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)