From 5d0a6ab0e96bc383a8ba1bf7669ca3c4aea0279d Mon Sep 17 00:00:00 2001 From: Rogan Lynch Date: Tue, 9 Dec 2025 19:22:57 -0800 Subject: [PATCH] fix: list-routes command now respects identifier filter with JSON output Fixes #2927 In v0.27.0, the list-routes command with -i flag and -o json output was returning all nodes instead of just the specified node. The issue was that JSON output was happening before the identifier filtering logic. This change moves the JSON output to after both the identifier filter and route existence filter are applied, ensuring the correct filtered results are returned. This restores the v0.26.1 behavior where: headscale nodes list-routes -i 12 -o json correctly returns only node 12's route information. --- cmd/headscale/cli/nodes.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index 8b4ab1ed..7d2cb677 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -220,10 +220,6 @@ var listNodeRoutesCmd = &cobra.Command{ ) } - if output != "" { - SuccessOutput(response.GetNodes(), "", output) - } - nodes := response.GetNodes() if identifier != 0 { for _, node := range response.GetNodes() { @@ -238,6 +234,11 @@ var listNodeRoutesCmd = &cobra.Command{ return (n.GetSubnetRoutes() != nil && len(n.GetSubnetRoutes()) > 0) || (n.GetApprovedRoutes() != nil && len(n.GetApprovedRoutes()) > 0) || (n.GetAvailableRoutes() != nil && len(n.GetAvailableRoutes()) > 0) }) + if output != "" { + SuccessOutput(nodes, "", output) + return + } + tableData, err := nodeRoutesToPtables(nodes) if err != nil { ErrorOutput(err, fmt.Sprintf("Error converting to table: %s", err), output)