run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
void run() {
if (!ContextService.isInitialized()) {
print('ContextForge has not been initialized.\nRun: contextforge init');
return;
}
if ((argResults?.rest.length ?? 0) < 2) {
print('Error: Task ID and status are required.');
print('Usage: contextforge task status <task-id> <status>');
print('Status options: todo, in-progress, completed');
return;
}
final taskId = argResults!.rest[0];
final newStatus = argResults!.rest[1];
if (!_validateStatus(newStatus)) {
print('Error: Invalid status "$newStatus"');
print('Valid options: todo, in-progress, completed');
return;
}
ContextService.ensureDataFilesExist();
final features = ContextService.loadAllFeatures();
final taskIndex = features.indexWhere((f) => f.id == taskId);
if (taskIndex == -1) {
print('Error: Task "$taskId" not found.');
return;
}
final task = features[taskIndex];
features[taskIndex] = Feature(
id: task.id,
title: task.title,
status: newStatus,
description: task.description,
files: task.files,
detailFile: task.detailFile,
);
ContextService.saveFeatures(features);
print('✔ Task "${task.title}" status updated to "$newStatus"');
}