diff --git a/client/cmd/debug.go b/client/cmd/debug.go index 761fc8b7260..da5e0945af7 100644 --- a/client/cmd/debug.go +++ b/client/cmd/debug.go @@ -59,7 +59,7 @@ var forCmd = &cobra.Command{ } func debugBundle(cmd *cobra.Command, _ []string) error { - conn, err := getClient(cmd.Context()) + conn, err := getClient(cmd) if err != nil { return err } @@ -80,7 +80,7 @@ func debugBundle(cmd *cobra.Command, _ []string) error { } func setLogLevel(cmd *cobra.Command, args []string) error { - conn, err := getClient(cmd.Context()) + conn, err := getClient(cmd) if err != nil { return err } @@ -109,7 +109,7 @@ func runForDuration(cmd *cobra.Command, args []string) error { return fmt.Errorf("invalid duration format: %v", err) } - conn, err := getClient(cmd.Context()) + conn, err := getClient(cmd) if err != nil { return err } diff --git a/client/cmd/root.go b/client/cmd/root.go index 1eca27d8c3e..83938071257 100644 --- a/client/cmd/root.go +++ b/client/cmd/root.go @@ -353,8 +353,11 @@ func migrateToNetbird(oldPath, newPath string) bool { return true } -func getClient(ctx context.Context) (*grpc.ClientConn, error) { - conn, err := DialClientGRPCServer(ctx, daemonAddr) +func getClient(cmd *cobra.Command) (*grpc.ClientConn, error) { + SetFlagsFromEnvVars(rootCmd) + cmd.SetOut(cmd.OutOrStdout()) + + conn, err := DialClientGRPCServer(cmd.Context(), daemonAddr) if err != nil { return nil, fmt.Errorf("failed to connect to daemon error: %v\n"+ "If the daemon is not running please run: "+ diff --git a/client/cmd/route.go b/client/cmd/route.go index 95cedb8baa2..d92e079adc6 100644 --- a/client/cmd/route.go +++ b/client/cmd/route.go @@ -49,7 +49,7 @@ func init() { } func routesList(cmd *cobra.Command, _ []string) error { - conn, err := getClient(cmd.Context()) + conn, err := getClient(cmd) if err != nil { return err } @@ -79,7 +79,7 @@ func routesList(cmd *cobra.Command, _ []string) error { } func routesSelect(cmd *cobra.Command, args []string) error { - conn, err := getClient(cmd.Context()) + conn, err := getClient(cmd) if err != nil { return err } @@ -106,7 +106,7 @@ func routesSelect(cmd *cobra.Command, args []string) error { } func routesDeselect(cmd *cobra.Command, args []string) error { - conn, err := getClient(cmd.Context()) + conn, err := getClient(cmd) if err != nil { return err }