parseConfigFile static method

Future<GlobalConfigNullable> parseConfigFile()

Implementation

static Future<GlobalConfigNullable> parseConfigFile() async {
  try {
    final homeDirectory = Platform.environment['HOME'];
    Log.d(_kTag, 'parseConfigFile homeDirectory=$homeDirectory');
    if (homeDirectory == null) return GlobalConfigNullable();

    final configFilePath = '$homeDirectory/.config/convenient_test.json';
    Log.d(_kTag, 'parseConfigFile configFilePath=$configFilePath');

    if (!await File(configFilePath).exists()) return GlobalConfigNullable();

    final configText = await File(configFilePath).readAsString();
    return GlobalConfigNullable.fromJson(jsonDecode(configText) as Map<String, Object?>);
  } catch (e, s) {
    Log.w(_kTag, 'parseConfigFile error e=$e s=$s');
    return GlobalConfigNullable();
  }
}