Skip to content

Commit 1867888

Browse files
committed
follow targets support
1 parent b3a1ec6 commit 1867888

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

cmd/lcode-hub/main.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path/filepath"
1111
"regexp"
12+
"strings"
1213
"time"
1314

1415
"github.com/alessio/shellescape"
@@ -60,11 +61,30 @@ func main() {
6061
fmt.Println("client connected", c.ID)
6162
defer fmt.Println("client disconnected", c.ID)
6263
f := format.FindStringSubmatch(c.ID)
63-
if len(f) == 3 {
64-
id := fmt.Sprintf("%s-%s", f[2], f[1])
65-
hello := fmt.Sprintf(args.hello, id, c.PWD)
64+
if len(f) != 3 {
65+
return
66+
}
67+
id := fmt.Sprintf("%s-%s", f[2], f[1])
68+
noEditTargets := true
69+
for _, t := range c.Targets() {
70+
var hello string
71+
switch {
72+
case strings.HasPrefix(t, "/dev/null"):
73+
t = strings.TrimPrefix(t, "/dev/null")
74+
hello = fmt.Sprintf("this target is not exists: %s", t)
75+
case strings.HasPrefix(t, "/dev/err"):
76+
t = strings.TrimPrefix(t, "/dev/err")
77+
hello = fmt.Sprintf("this target cannot be opened: %s", t)
78+
default:
79+
noEditTargets = false
80+
hello = fmt.Sprintf(args.hello, id, t)
81+
}
6682
c.Exec(fmt.Sprintf(">&2 echo lo: %s", shellescape.Quote(hello)))
6783
}
84+
if noEditTargets {
85+
c.Exec(fmt.Sprintf(">&2 echo lo: no editable targets, exit"))
86+
c.Close()
87+
}
6888
<-c.Closed()
6989
}(client)
7090
}

0 commit comments

Comments
 (0)