cmd/headscale/cli: remove nil resp guards and unexport HasMachineOutputFlag
Some checks are pending
Build / build-nix (push) Waiting to run
Build / build-cross (GOARCH=amd64 GOOS=darwin) (push) Waiting to run
Build / build-cross (GOARCH=amd64 GOOS=linux) (push) Waiting to run
Build / build-cross (GOARCH=arm64 GOOS=darwin) (push) Waiting to run
Build / build-cross (GOARCH=arm64 GOOS=linux) (push) Waiting to run
Check Generated Files / check-generated (push) Waiting to run
NixOS Module Tests / nix-module-check (push) Waiting to run
Tests / test (push) Waiting to run

Remove dead if-resp-nil checks in tagCmd and approveRoutesCmd; gRPC
returns either an error or a valid response, never (nil, nil).

Rename HasMachineOutputFlag to hasMachineOutputFlag since it has a
single internal caller in root.go.
This commit is contained in:
Kristoffer Dalby
2026-02-18 15:28:09 +00:00
parent af777f44f4
commit 13ebea192c
3 changed files with 12 additions and 21 deletions

View File

@@ -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")
}),
}

View File

@@ -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.

View File

@@ -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