diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index b28d66cd..dbc7e8bf 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -368,27 +368,26 @@ func nodesToPtables( tagsBuilder.WriteString("\n" + tag) } - tags := tagsBuilder.String() + tags := strings.TrimLeft(tagsBuilder.String(), "\n") var user string if node.GetUser() != nil { user = node.GetUser().GetName() } - var ( - ipAddresses string - ipAddressesSb485 strings.Builder - ) + var ipBuilder strings.Builder for _, addr := range node.GetIpAddresses() { ip, err := netip.ParseAddr(addr) if err == nil { - ipAddressesSb485.WriteString(ip.String() + "\n") + if ipBuilder.Len() > 0 { + ipBuilder.WriteString("\n") + } + + ipBuilder.WriteString(ip.String()) } } - ipAddresses += ipAddressesSb485.String() - - ipAddresses = strings.TrimRight(ipAddresses, "\n") + ipAddresses := ipBuilder.String() nodeData := []string{ strconv.FormatUint(node.GetId(), util.Base10), @@ -462,11 +461,7 @@ var tagCmd = &cobra.Command{ return fmt.Errorf("setting tags: %w", err) } - if resp != nil { - return printOutput(cmd, resp.GetNode(), "Node updated") - } - - return nil + return printOutput(cmd, resp.GetNode(), "Node updated") }), } @@ -488,10 +483,6 @@ var approveRoutesCmd = &cobra.Command{ return fmt.Errorf("setting approved routes: %w", err) } - if resp != nil { - return printOutput(cmd, resp.GetNode(), "Node updated") - } - - return nil + return printOutput(cmd, resp.GetNode(), "Node updated") }), } diff --git a/cmd/headscale/cli/root.go b/cmd/headscale/cli/root.go index 66241bce..a8a9bf69 100644 --- a/cmd/headscale/cli/root.go +++ b/cmd/headscale/cli/root.go @@ -61,7 +61,7 @@ func initConfig() { } } - machineOutput := HasMachineOutputFlag() + machineOutput := hasMachineOutputFlag() // If the user has requested a "node" readable format, // then disable login so the output remains valid. diff --git a/cmd/headscale/cli/utils.go b/cmd/headscale/cli/utils.go index 054d62d4..f5bf47f8 100644 --- a/cmd/headscale/cli/utils.go +++ b/cmd/headscale/cli/utils.go @@ -295,7 +295,7 @@ func printError(err error, outputFormat string) { fmt.Fprintf(os.Stderr, "%s\n", formatted) } -func HasMachineOutputFlag() bool { +func hasMachineOutputFlag() bool { for _, arg := range os.Args { if arg == outputFormatJSON || arg == outputFormatJSONLine || arg == outputFormatYAML { return true