Home > OS >  Working around "expanding an array only gives first element" (SC2128)
Working around "expanding an array only gives first element" (SC2128)

Time:12-02

Problem

I'm trying to save a few CLI arguments into a variable, so it's convenient for me to use later. This works but is quite verbose:

  • flutter run --dart-define=SENTRY_DSN_CLIENT_KEY=${APP1_SENTRY_DSN_CLIENT_KEY} --dart-define=MAPBOX_ACCESS_TOKEN=${APP1_MAPBOX_ACCESS_TOKEN}

Unfortunately, neither of the following, concise options work. The 2nd --dart-define is not available in the app. I've tried:

  • flutter run $APP1_DART_DEFINE_FLAGS
  • flutter run "${APP1_DART_DEFINE_FLAGS[@]}"

How do I workaround an issue which seems to be inside the flutter run tool?


Related problems

This seems to be highly related to (but I don't have control over fixing this):

My env file

export APP1_SENTRY_DSN_CLIENT_KEY=...
export APP1_MAPBOX_ACCESS_TOKEN=...
export APP1_DART_DEFINE_FLAGS="--dart-define=SENTRY_DSN_CLIENT_KEY=${APP1_SENTRY_DSN_CLIENT_KEY} --dart-define=MAPBOX_ACCESS_TOKEN=${APP1_MAPBOX_ACCESS_TOKEN}"

CodePudding user response:

Use bash arrays. Properly quote arguments.

APP1_DART_DEFINE_FLAGS=(
   "--dart-define=SENTRY_DSN_CLIENT_KEY=${APP1_SENTRY_DSN_CLIENT_KEY}"
   "--dart-define=MAPBOX_ACCESS_TOKEN=${APP1_MAPBOX_ACCESS_TOKEN}"
)
flutter run "${APP1_DART_DEFINE_FLAGS[@]}"
  • Related