Skip to content

Commit 78d89df

Browse files
committed
Improve clarity and consistency of error messages by using descriptive
operation names when calling findSingleUser across all CLI commands.
1 parent a32b156 commit 78d89df

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

cmd/headscale/cli/nodes.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var registerNodeCmd = &cobra.Command{
9595
defer cancel()
9696
defer conn.Close()
9797

98-
user, err := findSingleUser(ctx, client, cmd, "register Node", output)
98+
user, err := findSingleUser(ctx, client, cmd, "registerNodeCmd", output)
9999
if err != nil {
100100
// The helper already calls ErrorOutput, so we can just return
101101
return
@@ -156,7 +156,7 @@ var listNodesCmd = &cobra.Command{
156156

157157
// Only filter by user if user flags are provided
158158
if id >= 0 || username != "" {
159-
user, err := findSingleUser(ctx, client, cmd, "list", output)
159+
user, err := findSingleUser(ctx, client, cmd, "listNodesCmd", output)
160160
if err != nil {
161161
// The helper already calls ErrorOutput, so we can just return
162162
return
@@ -199,7 +199,7 @@ var listNodeRoutesCmd = &cobra.Command{
199199
Aliases: []string{"lsr", "routes"},
200200
Run: func(cmd *cobra.Command, args []string) {
201201
output, _ := cmd.Flags().GetString("output")
202-
identifier, err := cmd.Flags().GetUint64("identifier")
202+
identifier, err := cmd.Flags().GetUint64("node-id")
203203
if err != nil {
204204
ErrorOutput(
205205
err,
@@ -267,7 +267,7 @@ var expireNodeCmd = &cobra.Command{
267267
Run: func(cmd *cobra.Command, args []string) {
268268
output, _ := cmd.Flags().GetString("output")
269269

270-
identifier, err := cmd.Flags().GetUint64("identifier")
270+
identifier, err := cmd.Flags().GetUint64("node-id")
271271
if err != nil {
272272
ErrorOutput(
273273
err,
@@ -310,7 +310,7 @@ var renameNodeCmd = &cobra.Command{
310310
Run: func(cmd *cobra.Command, args []string) {
311311
output, _ := cmd.Flags().GetString("output")
312312

313-
identifier, err := cmd.Flags().GetUint64("identifier")
313+
identifier, err := cmd.Flags().GetUint64("node-id")
314314
if err != nil {
315315
ErrorOutput(
316316
err,
@@ -359,7 +359,7 @@ var deleteNodeCmd = &cobra.Command{
359359
Run: func(cmd *cobra.Command, args []string) {
360360
output, _ := cmd.Flags().GetString("output")
361361

362-
identifier, err := cmd.Flags().GetUint64("identifier")
362+
identifier, err := cmd.Flags().GetUint64("node-id")
363363
if err != nil {
364364
ErrorOutput(
365365
err,
@@ -463,7 +463,7 @@ var moveNodeCmd = &cobra.Command{
463463
defer cancel()
464464
defer conn.Close()
465465

466-
user, err := findSingleUser(ctx, client, cmd, "move Node", output)
466+
user, err := findSingleUser(ctx, client, cmd, "moveNodeCmd", output)
467467
if err != nil {
468468
// The helper already calls ErrorOutput, so we can just return
469469
return
@@ -745,7 +745,7 @@ var tagCmd = &cobra.Command{
745745
defer conn.Close()
746746

747747
// retrieve flags from CLI
748-
identifier, err := cmd.Flags().GetUint64("identifier")
748+
identifier, err := cmd.Flags().GetUint64("node-id")
749749
if err != nil {
750750
ErrorOutput(
751751
err,
@@ -802,7 +802,7 @@ var approveRoutesCmd = &cobra.Command{
802802
defer conn.Close()
803803

804804
// retrieve flags from CLI
805-
identifier, err := cmd.Flags().GetUint64("identifier")
805+
identifier, err := cmd.Flags().GetUint64("node-id")
806806
if err != nil {
807807
ErrorOutput(
808808
err,

cmd/headscale/cli/preauthkeys.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ var listPreAuthKeys = &cobra.Command{
6161
defer cancel()
6262
defer conn.Close()
6363

64-
user, err := findSingleUser(ctx, client, cmd, "list", output)
64+
user, err := findSingleUser(ctx, client, cmd, "listPreAuthKeys", output)
6565
if err != nil {
66+
// The helper already calls ErrorOutput, so we can just return
6667
return
6768
}
6869

@@ -145,8 +146,9 @@ var createPreAuthKeyCmd = &cobra.Command{
145146
defer cancel()
146147
defer conn.Close()
147148

148-
user, err := findSingleUser(ctx, client, cmd, "list", output)
149+
user, err := findSingleUser(ctx, client, cmd, "createPreAuthKeyCmd", output)
149150
if err != nil {
151+
// The helper already calls ErrorOutput, so we can just return
150152
return
151153
}
152154

@@ -211,8 +213,9 @@ var expirePreAuthKeyCmd = &cobra.Command{
211213
defer cancel()
212214
defer conn.Close()
213215

214-
user, err := findSingleUser(ctx, client, cmd, "list", output)
216+
user, err := findSingleUser(ctx, client, cmd, "expirePreAuthKeyCmd", output)
215217
if err != nil {
218+
// The helper already calls ErrorOutput, so we can just return
216219
return
217220
}
218221

cmd/headscale/cli/users.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var destroyUserCmd = &cobra.Command{
112112
defer cancel()
113113
defer conn.Close()
114114

115-
user, err := findSingleUser(ctx, client, cmd, "rename", output)
115+
user, err := findSingleUser(ctx, client, cmd, "destroyUserCmd", output)
116116
if err != nil {
117117
// The helper already calls ErrorOutput, so we can just return
118118
return
@@ -232,7 +232,7 @@ var renameUserCmd = &cobra.Command{
232232
defer cancel()
233233
defer conn.Close()
234234

235-
user, err := findSingleUser(ctx, client, cmd, "rename", output)
235+
user, err := findSingleUser(ctx, client, cmd, "renameUserCmd", output)
236236
if err != nil {
237237
// The helper already calls ErrorOutput, so we can just return
238238
return

0 commit comments

Comments
 (0)