parse method
Implementation
Map<String, dynamic> parse({List<String> commandLine = const []}) {
debugPrint('[Flutter ENV] Parsing command line arguments ...');
debugPrint('[Flutter ENV] Command line: $commandLine');
Map<String, dynamic> result = {};
for (var i = 0; i < commandLine.length; i += 2) {
var key = commandLine[i];
dynamic value = i + 1 < commandLine.length ? commandLine[i + 1] : true;
// Remove leading dashes from the key
key = key.replaceFirst(RegExp(r'^-+'), '');
// Assume a flag (key with no value) if the next item is another key or if it's the last item
if (value is String && value.startsWith('-') || i + 1 == commandLine.length) {
value = true;
i--; // Adjust the index to re-evaluate this item as a key in the next iteration
}
result[key] = value;
}
debugPrint('[Flutter ENV] Command line arguments: $result');
return result;
}