Skip to content

Commit 2dc16b8

Browse files
committed
Make ports positional arguments
1 parent 317cd29 commit 2dc16b8

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

ensure.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package main
22

33
import (
44
"context"
5+
"flag"
56
"fmt"
67
"os"
78
"strconv"
8-
"strings"
99
"time"
1010

1111
"github.com/outcatcher/fwd2me/forwarder"
@@ -18,11 +18,11 @@ var (
1818

1919
// keepForwarded makes sure ports are forwarded as long as possible without using a long lease.
2020
func keepForwarded(ctx context.Context) error {
21-
if *portsStr == "" {
22-
return fmt.Errorf("no ports given")
23-
}
21+
portSlice := flag.Args()
2422

25-
portSlice := strings.Split(*portsStr, ",")
23+
if len(portSlice) == 0 {
24+
return fmt.Errorf("empty port list")
25+
}
2626

2727
ports := make([]uint16, 0, len(portSlice))
2828

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ import (
1010
)
1111

1212
var (
13-
portsStr = flag.String("ports", "", "Comma-separated list of ports to forward (REQUIRED)")
14-
proto = flag.String("proto", "TCP", "Forwarded port protocol")
15-
label = flag.String("label", "fwd2me", "Label for the forwarding")
13+
proto = flag.String("proto", "TCP", "Forwarded port protocol")
14+
label = flag.String("label", "fwd2me", "Label for the forwarding")
1615
)
1716

1817
func main() {
18+
flag.Usage = func() {
19+
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s [options] [port1 port2 ...]:\n", os.Args[0])
20+
flag.PrintDefaults()
21+
}
22+
1923
flag.Parse()
2024

2125
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)