mirror of
https://github.com/juanfont/headscale.git
synced 2026-04-13 04:19:54 +02:00
cmd/headscale/cli: drop dead flag-read error checks
Flags registered on a cobra.Command cannot fail to read at runtime; GetString/GetUint64/GetStringSlice only error when the flag name is unknown. The error-handling blocks for these calls are unreachable dead code. Adopt the value, _ := pattern already used in api_key.go, preauthkeys.go and users.go, removing ~40 lines of dead code from nodes.go and debug.go.
This commit is contained in:
@@ -38,30 +38,16 @@ var createNodeCmd = &cobra.Command{
|
||||
Use: "create-node",
|
||||
Short: "Create a node that can be registered with `nodes register <>` command",
|
||||
RunE: grpcRunE(func(ctx context.Context, client v1.HeadscaleServiceClient, cmd *cobra.Command, args []string) error {
|
||||
user, err := cmd.Flags().GetString("user")
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting user flag: %w", err)
|
||||
}
|
||||
user, _ := cmd.Flags().GetString("user")
|
||||
name, _ := cmd.Flags().GetString("name")
|
||||
registrationID, _ := cmd.Flags().GetString("key")
|
||||
|
||||
name, err := cmd.Flags().GetString("name")
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting name flag: %w", err)
|
||||
}
|
||||
|
||||
registrationID, err := cmd.Flags().GetString("key")
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting key flag: %w", err)
|
||||
}
|
||||
|
||||
_, err = types.RegistrationIDFromString(registrationID)
|
||||
_, err := types.RegistrationIDFromString(registrationID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing machine key: %w", err)
|
||||
}
|
||||
|
||||
routes, err := cmd.Flags().GetStringSlice("route")
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting routes flag: %w", err)
|
||||
}
|
||||
routes, _ := cmd.Flags().GetStringSlice("route")
|
||||
|
||||
request := &v1.DebugCreateNodeRequest{
|
||||
Key: registrationID,
|
||||
|
||||
Reference in New Issue
Block a user