loadConfigFileFromArgResults function
Call loadConfigFile with arguments inferred from argResults
.
If an error occurs and the (optional) verbose
is true, log
a description to stderr.
Treat the current working directory as cwd
(if given), else,
use './' as the current working directory.
Note: cwd
was added to allow tests that require different
working directories to run at the same time, without conflicting.
Implementation
Map<String, dynamic> loadConfigFileFromArgResults(ArgResults argResults,
{bool? verbose, String? cwd}) {
verbose ??= false;
cwd ??= './';
String? configFile = argResults[fileOption];
final String? fileOptionResult = argResults[fileOption];
if (configFile != null) {
configFile = path.join(cwd, configFile);
}
// if icon is given, try to load icon
if (configFile != null && configFile != defaultConfigFile) {
try {
return loadConfigFile(configFile, fileOptionResult);
} catch (e) {
if (verbose) {
stderr.writeln(e);
}
return <String, dynamic>{};
}
}
// If none set try flutter_launcher_icons.yaml first then pubspec.yaml
// for compatibility
try {
return loadConfigFile(path.join(cwd, defaultConfigFile), fileOptionResult);
} catch (e) {
// Try pubspec.yaml for compatibility
if (configFile == null) {
try {
return loadConfigFile(path.join(cwd, 'pubspec.yaml'), fileOptionResult);
} catch (_) {}
}
// if nothing got returned, print error
if (verbose) {
stderr.writeln(e);
}
}
return <String, dynamic>{};
}