-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.go
More file actions
131 lines (111 loc) · 2.78 KB
/
utils.go
File metadata and controls
131 lines (111 loc) · 2.78 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package cmd
import (
"fmt"
"io"
"os"
"sort"
"strings"
"time"
drycc "github.com/drycc/controller-sdk-go"
"github.com/drycc/workflow-cli/pkg/git"
"github.com/drycc/workflow-cli/settings"
"github.com/olekukonko/tablewriter"
)
var defaultLimit = -1
func progress(wOut io.Writer) chan bool {
frames := []string{"...", "o..", ".o.", "..o"}
backspaces := strings.Repeat("\b", 3)
tick := time.NewTicker(400 * time.Millisecond)
quit := make(chan bool)
go func() {
for {
for _, frame := range frames {
fmt.Fprint(wOut, frame)
select {
case <-quit:
fmt.Fprint(wOut, backspaces)
close(quit)
return
case <-tick.C:
fmt.Fprint(wOut, backspaces)
}
}
}
}()
return quit
}
// load loads settings file and looks up the app name
func load(cf string, appID string) (*settings.Settings, string, error) {
s, err := settings.Load(cf)
if err != nil {
return nil, "", err
}
if appID == "" {
appID, err = git.DetectAppName(git.DefaultCmd, s.Client.ControllerURL.Host)
if err != nil {
return nil, "", err
}
}
return s, appID, nil
}
func drinkOfChoice() string {
drink := os.Getenv("DRYCC_DRINK_OF_CHOICE")
if drink == "" {
drink = "coffee"
}
return drink
}
func limitCount(objs, total int) string {
if objs == total {
return "\n"
}
return fmt.Sprintf(" (%d of %d)\n", objs, total)
}
// checkAPICompatibility handles specific behavior for certain errors,
// such as printing an warning for the API mismatch error
func (d *DryccCmd) checkAPICompatibility(c *drycc.Client, err error) error {
if err == drycc.ErrAPIMismatch {
if !d.Warned {
d.PrintErrf(`! WARNING: Client and server API versions do not match. Please consider upgrading.
! Client version: %s
! Server version: %s
`, drycc.APIVersion, c.ControllerAPIVersion)
d.Warned = true
}
// API mismatch isn't fatal, so after warning continue on.
return nil
}
return err
}
// getDefaultFormatTable return default format ascii table
func (d *DryccCmd) getDefaultFormatTable(headers []string) *tablewriter.Table {
table := tablewriter.NewWriter(d.WOut)
table.SetHeader(headers)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding(fmt.Sprintf("%4s", " "))
table.SetNoWhiteSpace(true)
return table
}
func sortKeys(data map[string]interface{}) *[]string {
keys := make([]string, 0, len(data))
for k := range data {
keys = append(keys, k)
}
sort.Strings(keys)
return &keys
}
func safeGetString(data string) string {
if data == "" {
return "<none>"
}
return data
}