-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathaccount.go
71 lines (64 loc) · 1.67 KB
/
account.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"fmt"
"os"
"strings"
"github.com/la5nta/pat/internal/cmsapi"
)
func shiftArgs(s []string) (string, []string) {
if len(s) == 0 {
return "", nil
}
return strings.TrimSpace(s[0]), s[1:]
}
const (
accountUsage = `property [value]
properties:
password.recovery.email
`
accountExample = `
account password.recovery.email Get your current password recovery email for winlink.org.
account password.recovery.email [email protected] Set your password recovery email to for winlink.org to "[email protected]".
`
)
func accountHandle(ctx context.Context, args []string) {
switch cmd, args := shiftArgs(args); cmd {
case "password.recovery.email":
if err := passwordRecoveryEmailHandle(ctx, args); err != nil {
fmt.Println("ERROR:", err)
os.Exit(1)
}
default:
fmt.Println("Missing argument, try 'account help'.")
}
}
func passwordRecoveryEmailHandle(ctx context.Context, args []string) error {
mycall, password := fOptions.MyCall, config.SecureLoginPassword
if password == "" {
select {
case <-ctx.Done():
return ctx.Err()
case resp := <-promptHub.Prompt("password", "Enter account password for "+mycall):
if resp.Err != nil {
return resp.Err
}
password = resp.Value
}
}
arg, _ := shiftArgs(args)
if arg != "" {
if err := cmsapi.PasswordRecoveryEmailSet(ctx, mycall, password, arg); err != nil {
return fmt.Errorf("failed to set value: %w", err)
}
}
email, err := cmsapi.PasswordRecoveryEmailGet(ctx, mycall, password)
switch {
case err != nil:
return fmt.Errorf("failed to get value: %w", err)
case strings.TrimSpace(email) == "":
email = "[not set]"
}
fmt.Println(email)
return nil
}