-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (59 loc) · 1.41 KB
/
main.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
package main
import (
"fmt"
"os"
"time"
"strings"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Error: no action specified.")
os.Exit(1)
}
action := os.Args[1]
fmt.Printf("Performing %s...\n", action)
switch action {
case "build":
doActionWithLoadingAnimation("Building")
case "deploy":
doActionWithLoadingAnimation("Deploying")
case "run":
doActionWithLoadingAnimation("Running")
case "upgrade":
doActionWithLoadingAnimation("Upgrading")
case "install":
doActionWithLoadingAnimation("Installing")
default:
fmt.Printf("Error: invalid action '%s'.\n", action)
os.Exit(1)
}
}
func doActionWithLoadingAnimation(action string) (bool) {
fmt.Printf("%s:\n", action)
// Define the loading animation
animation := []string{
"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷",
}
// Start the progress bar
fmt.Print("[")
for i := 0; i < 40; i++ {
fmt.Print(" ")
}
fmt.Print("]\r[")
for i := 0; i < 40; i++ {
fmt.Print(" ")
}
fmt.Print("]\r")
// Loop to update the progress bar and display the loading animation
for i := 0; i < 100; i++ {
index := i % len(animation)
if i < 0 || i / 2 < 0 || 39-i/2 < 0 {
continue
}
fmt.Printf("\033[1;34m%s\033[0m[%-40s]%3d%%\r", animation[index], strings.Repeat("=", i/2)+">"+strings.Repeat(" ", 39-i/2), i)
time.Sleep(30 * time.Millisecond)
}
// Print the "Done!" message
fmt.Println("\n\033[1;32mDone!\033[0m")
return true
}