dart2dsl function
Implementation
Future dart2dsl(List<String> arguments) async {
final parser = ArgParser()
..addOption('file', abbr: 'f')
..addOption('directory', abbr: 'd')
..addOption('output-directory', abbr: 'o')
..addOption('sdk-name', abbr: 's')
..addOption('source-path', abbr: 'p')
..addOption('compile-kind',
abbr: 'k',
defaultsTo: 'bundle',
allowed: ['bundle', 'bundleDir', 'dart', 'flutter', 'sdk']);
var argResults = parser.parse(arguments);
var kind = argResults['compile-kind'];
if (kind == 'bundle') {
var file = argResults['file'];
if (file == null || !File(file).existsSync()) {
_error('file is required, please pass as absolute path');
}
return _appendResult(await dsl.parseFile(file, sourcePath: argResults['source-path']));
} else if (kind == 'bundleDir') {
var dirString = argResults['directory'];
if (dirString == null || !Directory(dirString).existsSync()) {
print('directory is not valid, please pass as absolute path');
exit(1);
}
return _appendResult(await dsl.parseDir(dirString));
} else if (kind == 'dart') {
var dirString = argResults['directory'];
Directory? dir;
if (dirString == null || !(dir = Directory(dirString)).existsSync()) {
_error('directory is not valid, please pass as absolute path');
}
return _appendResult(await binding.parseDir(dir!));
} else if (kind == 'flutter') {
var dir = argResults['directory'];
if (dir == null || !(Directory(dir)).existsSync()) {
_error('directory is not valid, please pass as absolute path');
}
await binding.parseFlutter(dir);
} else if (kind == 'sdk'){
var file = argResults['file'];
var sdkName = argResults['sdk-name'];
var outputDir = argResults['output-directory'];
if (file == null || !File(file).existsSync()){
_error('file is required, please pass as absolute path');
}
var _output = 'sdk';
if(outputDir?.isNotEmpty == true){
_output = outputDir;
}
await binding.parseSdkFile(sdkName, file, _output);
}
}