From deffe037aafac7eb0a2b1483b1662a603e03e9f3 Mon Sep 17 00:00:00 2001 From: Viktor Liu <17948409+lixmal@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:59:10 +0200 Subject: [PATCH] Respect env for debug and routes sub commands (#2026) --- client/cmd/debug.go | 6 +++--- client/cmd/root.go | 7 +++++-- client/cmd/route.go | 6 +++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client/cmd/debug.go b/client/cmd/debug.go index 761fc8b72..da5e0945a 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 1eca27d8c..839380712 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 95cedb8ba..d92e079ad 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 }