-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjcliStart.go
More file actions
103 lines (82 loc) · 2.3 KB
/
Copy pathjcliStart.go
File metadata and controls
103 lines (82 loc) · 2.3 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func printError(errStr error) {
if errStr != nil {
fmt.Printf("\033[91m%s\033[0m\n", errStr)
}
}
func main() {
// Step 1: Request Device Code
fmt.Println("Welcome to the JamLaunch CLI!")
fmt.Print("Checking token...")
result, token := loadToken()
if !result {
fmt.Println("\033[91mToken not found or invalid! User must authenticate again.\033[0m")
var err error
token, err = getDevToken()
if err != nil {
fmt.Printf("\033[31mFailed to get tokens: %v\n - exiting...\033[0m\n", err)
}
} else {
fmt.Printf("\033[92mLogin successful!\033[0m\n")
}
reader := bufio.NewReader(os.Stdin)
fmt.Println("Type your message below. Type 'exit' to quit.")
for {
// Display a prompt
fmt.Print("> ")
// Read user input
input, err := reader.ReadString('\n')
if err != nil {
fmt.Printf("\033[91mError reading input: %s\033[0m\n", err)
continue
}
// Trim whitespace
input = strings.TrimSpace(input)
if strings.ToLower(input) == "login" {
err = login()
printError(err)
} else if len(input) >= 8 && strings.ToLower(input[:8]) == "projects" {
parts := strings.Fields(input)
if len(parts) == 1 && strings.ToLower(parts[0]) == "projects" {
err = projects(token)
printError(err)
} else if len(parts) == 2 {
err = projectsName(token, parts[1])
printError(err)
} else if len(parts) == 3 {
err = projectSessions(token, parts[1])
printError(err)
} else {
err = projectSessionId(token, parts[1], parts[3])
printError(err)
}
} else if len(input) >= 3 && strings.ToLower(input[:3]) == "get" {
parts := strings.Fields(input)
err = apiGet(parts[1], token)
printError(err)
} else if len(input) >= 8 && strings.ToLower(input[:8]) == "game-get" {
parts := strings.Fields(input)
gameToken, err := getGameUserToken(parts[1], token)
if err != nil {
fmt.Printf("\033[31mFailed: %v\033[0m\n", err)
continue
}
err = apiGet(parts[2], gameToken)
printError(err)
} else if len(input) >= 4 && strings.ToLower(input[:4]) == "help" {
help(input)
} else if strings.ToLower(input) == "exit" {
fmt.Println("Goodbye!")
break
} else {
fmt.Printf("\033[31m%s is not a valid command!\033[0m\n", input)
}
}
}
// https://admin-api.jamlaunch.com/account/transactions