handle method
Called automatically before executing the command. You can override to do pre-validation or setup.
Implementation
@override
Future<void> handle(List<String> args) async {
final input = argResults?['name'] as String?;
if (input == null || input.trim().isEmpty) {
logger.error('❌ Usage: khadem make:view --name=welcome');
exitCode = 1;
return;
}
final normalized = CliNaming.normalizePathInput(input);
final segments = normalized
.split('/')
.where((s) => s.trim().isNotEmpty)
.map(CliNaming.toSnakeCase)
.toList();
final viewName = segments.join('/');
final filePath = 'resources/views/$viewName.khdm.html';
final file = File(filePath);
if (await file.exists()) {
logger.error('❌ View already exists at $filePath');
exitCode = 1;
return;
}
await file.create(recursive: true);
await file.writeAsString(
'''
<!-- Khadem view: $viewName -->
<div>
<h1>$viewName</h1>
</div>
'''
.trim(),
);
logger.info('✅ View "$viewName" created at $filePath');
exitCode = 0;
}