createIconsFromArguments function

Future<void> createIconsFromArguments(
  1. List<String> arguments
)

Implementation

Future<void> createIconsFromArguments(List<String> arguments) async {
  final ArgParser parser = ArgParser(allowTrailingOptions: true);
  parser.addFlag(helpFlag, abbr: 'h', help: 'Usage help', negatable: false);

  // Make default null to differentiate when it is explicitly set
  parser.addOption(fileOption,
      abbr: 'f', help: 'Config file (default: $defaultConfigFile)');
  final ArgResults argResults = parser.parse(arguments);

  if (argResults[helpFlag]) {
    stdout.writeln('Generates icons for Android, iOS, MacOS, Windows and Web');
    stdout.writeln(parser.usage);
    exit(0);
  }

  // Flavors manangement
  final List<String> flavors = getFlavors();
  final bool hasFlavors = flavors.isNotEmpty;

  // Create icons
  if (!hasFlavors || argResults[fileOption] != null) {
    // Load the config file
    final Map<String, dynamic> yamlConfig =
        loadConfigFileFromArgResults(argResults, verbose: true);

    try {
      createIconsFromConfig(yamlConfig);
      print('\n✓ Successfully generated launcher icons');
    } catch (e) {
      stderr.writeln('\n✕ Could not generate launcher icons');
      stderr.writeln(e);
      exit(2);
    }
  } else {
    try {
      for (String flavor in flavors) {
        print('\nFlavor: $flavor');
        final Map<String, dynamic> yamlConfig =
            loadConfigFile(flavorConfigFile(flavor), flavorConfigFile(flavor));
        await createIconsFromConfig(yamlConfig, flavor);
      }
      print('\n✓ Successfully generated launcher icons for flavors');
    } catch (e) {
      stderr.writeln('\n✕ Could not generate launcher icons for flavors');
      stderr.writeln(e);
      exit(2);
    }
  }
}