Respect env for debug and routes sub commands (#2026)

This commit is contained in:
Viktor Liu 2024-06-06 10:59:10 +02:00 committed by GitHub
parent 983d7bafbe
commit deffe037aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 8 deletions

View File

@ -59,7 +59,7 @@ var forCmd = &cobra.Command{
} }
func debugBundle(cmd *cobra.Command, _ []string) error { func debugBundle(cmd *cobra.Command, _ []string) error {
conn, err := getClient(cmd.Context()) conn, err := getClient(cmd)
if err != nil { if err != nil {
return err return err
} }
@ -80,7 +80,7 @@ func debugBundle(cmd *cobra.Command, _ []string) error {
} }
func setLogLevel(cmd *cobra.Command, args []string) error { func setLogLevel(cmd *cobra.Command, args []string) error {
conn, err := getClient(cmd.Context()) conn, err := getClient(cmd)
if err != nil { if err != nil {
return err return err
} }
@ -109,7 +109,7 @@ func runForDuration(cmd *cobra.Command, args []string) error {
return fmt.Errorf("invalid duration format: %v", err) return fmt.Errorf("invalid duration format: %v", err)
} }
conn, err := getClient(cmd.Context()) conn, err := getClient(cmd)
if err != nil { if err != nil {
return err return err
} }

View File

@ -353,8 +353,11 @@ func migrateToNetbird(oldPath, newPath string) bool {
return true return true
} }
func getClient(ctx context.Context) (*grpc.ClientConn, error) { func getClient(cmd *cobra.Command) (*grpc.ClientConn, error) {
conn, err := DialClientGRPCServer(ctx, daemonAddr) SetFlagsFromEnvVars(rootCmd)
cmd.SetOut(cmd.OutOrStdout())
conn, err := DialClientGRPCServer(cmd.Context(), daemonAddr)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to connect to daemon error: %v\n"+ return nil, fmt.Errorf("failed to connect to daemon error: %v\n"+
"If the daemon is not running please run: "+ "If the daemon is not running please run: "+

View File

@ -49,7 +49,7 @@ func init() {
} }
func routesList(cmd *cobra.Command, _ []string) error { func routesList(cmd *cobra.Command, _ []string) error {
conn, err := getClient(cmd.Context()) conn, err := getClient(cmd)
if err != nil { if err != nil {
return err return err
} }
@ -79,7 +79,7 @@ func routesList(cmd *cobra.Command, _ []string) error {
} }
func routesSelect(cmd *cobra.Command, args []string) error { func routesSelect(cmd *cobra.Command, args []string) error {
conn, err := getClient(cmd.Context()) conn, err := getClient(cmd)
if err != nil { if err != nil {
return err return err
} }
@ -106,7 +106,7 @@ func routesSelect(cmd *cobra.Command, args []string) error {
} }
func routesDeselect(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 { if err != nil {
return err return err
} }