run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
Future<bool> run() async {
// Check for template param
String? tempName = templateName;
final needsTemplate = tempName?.isEmpty ?? true;
final closer = logger.printFixed(" 👀 Checking templates");
// If no template was specified
if (needsTemplate) {
tempName = await _selectTemplate();
if (tempName == null || tempName.isEmpty) {
return false; // Fail out, cannot proceed without a template
}
}
// Validate provided template exists in list
final tempList = await _getTemplateList();
if (!tempList.contains(tempName)) {
return false; // Fail out, cannot proceed with an invalid template
}
// Download selected template to temp dir
final tempDir = await _downloadTemplate(name: tempName!);
if (tempDir == null || tempDir.isEmpty) {
return closer(false, 'Template download failed.');
}
// Deploy without overwriting existing files
await _deployTemplateFiles(tempDir: tempDir);
// Run the template installer
await _installTemplate();
// Delete temp dir and template repo
if (tempDir.isNotEmpty) {
await _deleteTemplateLocal(tempDir: tempDir);
}
return closer(true, tempName);
}