Skip to content

Commit bdfd382

Browse files
authored
Merge pull request #209 from joostjager/fix-loop-cli-parse
cmd/loop: fix channel parsing
2 parents bd2d39b + a3924cf commit bdfd382

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cmd/loop/loopout.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,20 @@ func loopOut(ctx *cli.Context) error {
8989
return err
9090
}
9191

92-
// Parse outgoing channel set.
93-
chanStrings := strings.Split(ctx.String("channel"), ",")
92+
// Parse outgoing channel set. Don't string split if the flag is empty.
93+
// Otherwise strings.Split returns a slice of length one with an empty
94+
// element.
9495
var outgoingChanSet []uint64
95-
for _, chanString := range chanStrings {
96-
chanID, err := strconv.ParseUint(chanString, 10, 64)
97-
if err != nil {
98-
return err
96+
if ctx.IsSet("channel") {
97+
chanStrings := strings.Split(ctx.String("channel"), ",")
98+
for _, chanString := range chanStrings {
99+
chanID, err := strconv.ParseUint(chanString, 10, 64)
100+
if err != nil {
101+
return fmt.Errorf("error parsing channel id "+
102+
"\"%v\"", chanString)
103+
}
104+
outgoingChanSet = append(outgoingChanSet, chanID)
99105
}
100-
outgoingChanSet = append(outgoingChanSet, chanID)
101106
}
102107

103108
var destAddr string

0 commit comments

Comments
 (0)