mirror of
https://github.com/juanfont/headscale.git
synced 2026-02-20 19:50:30 +09:00
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
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:
@@ -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")
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user