mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
cmd/tailscale/cli: make 'debug watch-ipn' play nice with jq
jq doens't like non-json output in the json stream, and works more happily when the input stream EOFs at some point. Move non-json words to stderr, and add a parameter to stop watching and exit after some number of objects. Updates #cleanup Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
c4855fe0ea
commit
fd22145b52
@ -189,6 +189,7 @@ var debugCmd = &ffcli.Command{
|
|||||||
fs.BoolVar(&watchIPNArgs.netmap, "netmap", true, "include netmap in messages")
|
fs.BoolVar(&watchIPNArgs.netmap, "netmap", true, "include netmap in messages")
|
||||||
fs.BoolVar(&watchIPNArgs.initial, "initial", false, "include initial status")
|
fs.BoolVar(&watchIPNArgs.initial, "initial", false, "include initial status")
|
||||||
fs.BoolVar(&watchIPNArgs.showPrivateKey, "show-private-key", false, "include node private key in printed netmap")
|
fs.BoolVar(&watchIPNArgs.showPrivateKey, "show-private-key", false, "include node private key in printed netmap")
|
||||||
|
fs.IntVar(&watchIPNArgs.count, "count", 0, "exit after printing this many statuses, or 0 to keep going forever")
|
||||||
return fs
|
return fs
|
||||||
})(),
|
})(),
|
||||||
},
|
},
|
||||||
@ -416,6 +417,7 @@ var watchIPNArgs struct {
|
|||||||
netmap bool
|
netmap bool
|
||||||
initial bool
|
initial bool
|
||||||
showPrivateKey bool
|
showPrivateKey bool
|
||||||
|
count int
|
||||||
}
|
}
|
||||||
|
|
||||||
func runWatchIPN(ctx context.Context, args []string) error {
|
func runWatchIPN(ctx context.Context, args []string) error {
|
||||||
@ -431,8 +433,8 @@ func runWatchIPN(ctx context.Context, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer watcher.Close()
|
defer watcher.Close()
|
||||||
printf("Connected.\n")
|
fmt.Fprintf(os.Stderr, "Connected.\n")
|
||||||
for {
|
for seen := 0; watchIPNArgs.count == 0 || seen < watchIPNArgs.count; seen++ {
|
||||||
n, err := watcher.Next()
|
n, err := watcher.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -441,8 +443,9 @@ func runWatchIPN(ctx context.Context, args []string) error {
|
|||||||
n.NetMap = nil
|
n.NetMap = nil
|
||||||
}
|
}
|
||||||
j, _ := json.MarshalIndent(n, "", "\t")
|
j, _ := json.MarshalIndent(n, "", "\t")
|
||||||
printf("%s\n", j)
|
fmt.Printf("%s\n", j)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDERPMap(ctx context.Context, args []string) error {
|
func runDERPMap(ctx context.Context, args []string) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user