mirror of
https://github.com/juanfont/headscale.git
synced 2026-04-28 11:37:23 +02:00
cmd/headscale/cli: remove nil resp guards and unexport HasMachineOutputFlag
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)
|
tagsBuilder.WriteString("\n" + tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := tagsBuilder.String()
|
tags := strings.TrimLeft(tagsBuilder.String(), "\n")
|
||||||
|
|
||||||
var user string
|
var user string
|
||||||
if node.GetUser() != nil {
|
if node.GetUser() != nil {
|
||||||
user = node.GetUser().GetName()
|
user = node.GetUser().GetName()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var ipBuilder strings.Builder
|
||||||
ipAddresses string
|
|
||||||
ipAddressesSb485 strings.Builder
|
|
||||||
)
|
|
||||||
for _, addr := range node.GetIpAddresses() {
|
for _, addr := range node.GetIpAddresses() {
|
||||||
ip, err := netip.ParseAddr(addr)
|
ip, err := netip.ParseAddr(addr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ipAddressesSb485.WriteString(ip.String() + "\n")
|
if ipBuilder.Len() > 0 {
|
||||||
|
ipBuilder.WriteString("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
ipBuilder.WriteString(ip.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ipAddresses += ipAddressesSb485.String()
|
ipAddresses := ipBuilder.String()
|
||||||
|
|
||||||
ipAddresses = strings.TrimRight(ipAddresses, "\n")
|
|
||||||
|
|
||||||
nodeData := []string{
|
nodeData := []string{
|
||||||
strconv.FormatUint(node.GetId(), util.Base10),
|
strconv.FormatUint(node.GetId(), util.Base10),
|
||||||
@@ -462,11 +461,7 @@ var tagCmd = &cobra.Command{
|
|||||||
return fmt.Errorf("setting tags: %w", err)
|
return fmt.Errorf("setting tags: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp != nil {
|
return printOutput(cmd, resp.GetNode(), "Node updated")
|
||||||
return printOutput(cmd, resp.GetNode(), "Node updated")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,10 +483,6 @@ var approveRoutesCmd = &cobra.Command{
|
|||||||
return fmt.Errorf("setting approved routes: %w", err)
|
return fmt.Errorf("setting approved routes: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp != nil {
|
return printOutput(cmd, resp.GetNode(), "Node updated")
|
||||||
return printOutput(cmd, resp.GetNode(), "Node updated")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func initConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
machineOutput := HasMachineOutputFlag()
|
machineOutput := hasMachineOutputFlag()
|
||||||
|
|
||||||
// If the user has requested a "node" readable format,
|
// If the user has requested a "node" readable format,
|
||||||
// then disable login so the output remains valid.
|
// 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)
|
fmt.Fprintf(os.Stderr, "%s\n", formatted)
|
||||||
}
|
}
|
||||||
|
|
||||||
func HasMachineOutputFlag() bool {
|
func hasMachineOutputFlag() bool {
|
||||||
for _, arg := range os.Args {
|
for _, arg := range os.Args {
|
||||||
if arg == outputFormatJSON || arg == outputFormatJSONLine || arg == outputFormatYAML {
|
if arg == outputFormatJSON || arg == outputFormatJSONLine || arg == outputFormatYAML {
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user