-
Notifications
You must be signed in to change notification settings - Fork 13
/
cmd.go
49 lines (45 loc) · 933 Bytes
/
cmd.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
package main
import (
"strings"
)
type commandlist []string
var cmdlst = make(commandlist, 0, 64)
func (cl commandlist) String() string {
sb := strings.Builder{}
islastdir := false
isfirstloop := true
sb.WriteString(" ")
for _, cmd := range cmdlst {
if len(cmd) == 0 {
continue
}
trimedcmd := strings.TrimSuffix(cmd, "/")
a := strings.LastIndex(trimedcmd, "/") + 1
b := len(cmd) - 1
if a >= b {
continue
}
isdir := cmd[b] == '/'
ident := strings.Count(trimedcmd, "/") + 1
if !isfirstloop && (islastdir || isdir) {
sb.WriteByte('\n')
if !isdir {
ident--
}
for i := 0; i < ident; i++ {
sb.WriteString(" ")
}
}
isfirstloop = false
if isdir {
islastdir = true
sb.WriteString(cmd[a:b])
sb.WriteByte(':')
} else { // is file
islastdir = false
sb.WriteString(" ")
sb.WriteString(strings.TrimSuffix(cmd[a:], ".yaml"))
}
}
return sb.String()
}