DartDefinesCliCode.fromEnvironment constructor

DartDefinesCliCode.fromEnvironment({
  1. required String flavor,
  2. Map<String, String>? environment,
})

compose用に、対象の環境変数だけを取り込みます。

Implementation

factory DartDefinesCliCode.fromEnvironment({
  required String flavor,
  Map<String, String>? environment,
}) {
  final values = environment ?? Platform.environment;
  String? read(String key) {
    final value = values[key];
    if (value != null && (value.contains("\n") || value.contains("\r"))) {
      throw FormatException("$key に改行は指定できません。");
    }
    return value;
  }

  // Write references instead of the values so that secrets are not
  // stored in dart_defines/*.env. They are expanded at build time.
  return DartDefinesCliCode(
    flavor: flavor,
    aiDebuggerApiKey: read("MASAMUNE_AI_DEBUGGER_API_KEY") == null
        ? null
        : r"${MASAMUNE_AI_DEBUGGER_API_KEY:-}",
    aiDebuggerAccounts: read("MASAMUNE_AI_DEBUGGER_ACCOUNTS") == null
        ? null
        : r"${MASAMUNE_AI_DEBUGGER_ACCOUNTS:-}",
  );
}