From 78d89dff6b65fccec1a663390cd0f5a06694e129 Mon Sep 17 00:00:00 2001 From: Tevin Flores Date: Thu, 29 May 2025 15:42:23 -0400 Subject: [PATCH] Improve clarity and consistency of error messages by using descriptive operation names when calling findSingleUser across all CLI commands. --- cmd/headscale/cli/nodes.go | 18 +++++++++--------- cmd/headscale/cli/preauthkeys.go | 9 ++++++--- cmd/headscale/cli/users.go | 4 ++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index e6e90402..cf2914a3 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -95,7 +95,7 @@ var registerNodeCmd = &cobra.Command{ defer cancel() defer conn.Close() - user, err := findSingleUser(ctx, client, cmd, "register Node", output) + user, err := findSingleUser(ctx, client, cmd, "registerNodeCmd", output) if err != nil { // The helper already calls ErrorOutput, so we can just return return @@ -156,7 +156,7 @@ var listNodesCmd = &cobra.Command{ // Only filter by user if user flags are provided if id >= 0 || username != "" { - user, err := findSingleUser(ctx, client, cmd, "list", output) + user, err := findSingleUser(ctx, client, cmd, "listNodesCmd", output) if err != nil { // The helper already calls ErrorOutput, so we can just return return @@ -199,7 +199,7 @@ var listNodeRoutesCmd = &cobra.Command{ Aliases: []string{"lsr", "routes"}, Run: func(cmd *cobra.Command, args []string) { output, _ := cmd.Flags().GetString("output") - identifier, err := cmd.Flags().GetUint64("identifier") + identifier, err := cmd.Flags().GetUint64("node-id") if err != nil { ErrorOutput( err, @@ -267,7 +267,7 @@ var expireNodeCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { output, _ := cmd.Flags().GetString("output") - identifier, err := cmd.Flags().GetUint64("identifier") + identifier, err := cmd.Flags().GetUint64("node-id") if err != nil { ErrorOutput( err, @@ -310,7 +310,7 @@ var renameNodeCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { output, _ := cmd.Flags().GetString("output") - identifier, err := cmd.Flags().GetUint64("identifier") + identifier, err := cmd.Flags().GetUint64("node-id") if err != nil { ErrorOutput( err, @@ -359,7 +359,7 @@ var deleteNodeCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { output, _ := cmd.Flags().GetString("output") - identifier, err := cmd.Flags().GetUint64("identifier") + identifier, err := cmd.Flags().GetUint64("node-id") if err != nil { ErrorOutput( err, @@ -463,7 +463,7 @@ var moveNodeCmd = &cobra.Command{ defer cancel() defer conn.Close() - user, err := findSingleUser(ctx, client, cmd, "move Node", output) + user, err := findSingleUser(ctx, client, cmd, "moveNodeCmd", output) if err != nil { // The helper already calls ErrorOutput, so we can just return return @@ -745,7 +745,7 @@ var tagCmd = &cobra.Command{ defer conn.Close() // retrieve flags from CLI - identifier, err := cmd.Flags().GetUint64("identifier") + identifier, err := cmd.Flags().GetUint64("node-id") if err != nil { ErrorOutput( err, @@ -802,7 +802,7 @@ var approveRoutesCmd = &cobra.Command{ defer conn.Close() // retrieve flags from CLI - identifier, err := cmd.Flags().GetUint64("identifier") + identifier, err := cmd.Flags().GetUint64("node-id") if err != nil { ErrorOutput( err, diff --git a/cmd/headscale/cli/preauthkeys.go b/cmd/headscale/cli/preauthkeys.go index 620a349c..80910663 100644 --- a/cmd/headscale/cli/preauthkeys.go +++ b/cmd/headscale/cli/preauthkeys.go @@ -61,8 +61,9 @@ var listPreAuthKeys = &cobra.Command{ defer cancel() defer conn.Close() - user, err := findSingleUser(ctx, client, cmd, "list", output) + user, err := findSingleUser(ctx, client, cmd, "listPreAuthKeys", output) if err != nil { + // The helper already calls ErrorOutput, so we can just return return } @@ -145,8 +146,9 @@ var createPreAuthKeyCmd = &cobra.Command{ defer cancel() defer conn.Close() - user, err := findSingleUser(ctx, client, cmd, "list", output) + user, err := findSingleUser(ctx, client, cmd, "createPreAuthKeyCmd", output) if err != nil { + // The helper already calls ErrorOutput, so we can just return return } @@ -211,8 +213,9 @@ var expirePreAuthKeyCmd = &cobra.Command{ defer cancel() defer conn.Close() - user, err := findSingleUser(ctx, client, cmd, "list", output) + user, err := findSingleUser(ctx, client, cmd, "expirePreAuthKeyCmd", output) if err != nil { + // The helper already calls ErrorOutput, so we can just return return } diff --git a/cmd/headscale/cli/users.go b/cmd/headscale/cli/users.go index e3d138fc..638c077d 100644 --- a/cmd/headscale/cli/users.go +++ b/cmd/headscale/cli/users.go @@ -112,7 +112,7 @@ var destroyUserCmd = &cobra.Command{ defer cancel() defer conn.Close() - user, err := findSingleUser(ctx, client, cmd, "rename", output) + user, err := findSingleUser(ctx, client, cmd, "destroyUserCmd", output) if err != nil { // The helper already calls ErrorOutput, so we can just return return @@ -232,7 +232,7 @@ var renameUserCmd = &cobra.Command{ defer cancel() defer conn.Close() - user, err := findSingleUser(ctx, client, cmd, "rename", output) + user, err := findSingleUser(ctx, client, cmd, "renameUserCmd", output) if err != nil { // The helper already calls ErrorOutput, so we can just return return