-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathutils.go
More file actions
80 lines (64 loc) · 1.27 KB
/
utils.go
File metadata and controls
80 lines (64 loc) · 1.27 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
package cmd
import (
"fmt"
"os"
"strings"
"time"
"github.com/deis/deis/client-go/controller/client"
"github.com/deis/deis/client-go/pkg/git"
)
func progress() chan bool {
frames := []string{"...", "o..", ".o.", "..o"}
backspaces := strings.Repeat("\b", 3)
tick := time.Tick(400 * time.Millisecond)
quit := make(chan bool)
go func() {
for {
for _, frame := range frames {
fmt.Print(frame)
select {
case <-quit:
fmt.Print(backspaces)
close(quit)
return
case <-tick:
fmt.Print(backspaces)
}
}
}
}()
return quit
}
// Choose an ANSI color by converting a string to an int.
func chooseColor(input string) string {
var sum uint8
for _, char := range []byte(input) {
sum += uint8(char)
}
// Seven possible terminal colors
color := (sum % 7) + 1
if color == 7 {
color = 9
}
return fmt.Sprintf("\033[3%dm", color)
}
func load(appID string) (*client.Client, string, error) {
c, err := client.New()
if err != nil {
return nil, "", err
}
if appID == "" {
appID, err = git.DetectAppName(c.ControllerURL.Host)
if err != nil {
return nil, "", err
}
}
return c, appID, nil
}
func drinkOfChoice() string {
drink := os.Getenv("DEIS_DRINK_OF_CHOICE")
if drink == "" {
drink = "coffee"
}
return drink
}