-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.go
42 lines (40 loc) · 1.15 KB
/
update.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 main
import (
"bufio"
"encoding/gob"
"fmt"
"github.com/urfave/cli/v2"
"os"
"strings"
)
func update(c *cli.Context) error {
absPath := FilePathClean(configfile)
_, err := os.Stat(absPath)
if err != nil {
fmt.Println("Configuration not present, please use `init` or `add` to create configuration")
}
decodeFile, err := os.Open(absPath)
checkErr(err)
defer decodeFile.Close()
decoder := gob.NewDecoder(decodeFile)
accounts := make(map[string]Profile)
decoder.Decode(&accounts)
oldProfile := accounts[profile]
reader := bufio.NewReader(os.Stdin)
fmt.Println("Updating Profile: " + profile)
fmt.Print("Enter Access Key ID ", oldProfile.Keyid, "\t:")
keyid, err := reader.ReadString('\n')
keyid = strings.Replace(keyid, "\n", "", -1)
checkErr(err)
fmt.Print("Enter Secret Access Key ", oldProfile.Secretkey, "\t:")
secret, err := reader.ReadString('\n')
secret = strings.Replace(secret, "\n", "", -1)
checkErr(err)
device := getDeviceId(keyid, secret)
fmt.Println("Using Device ", device)
accounts[profile] = Profile{keyid, secret, device}
fmt.Println(accounts)
writeConfigToFile(accounts)
fmt.Println("update successful")
return nil
}