run method

  1. @override
void run()
override

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;
  }

  ContextService.ensureDataFilesExist();

  final showAll = argResults?['all'] as bool? ?? false;
  final features = showAll
      ? ContextService.loadAllFeatures()
      : ContextService.loadFeatures();

  if (features.isEmpty) {
    print(showAll
        ? 'No tasks tracked yet.\nRun: contextforge task add'
        : 'No active tasks. Run: contextforge task list --all to see completed.');
    return;
  }

  print('\nšŸ“‹ Tasks${showAll ? ' (all)' : ''}\n');

  final todo = features.where((f) => f.status == 'todo').toList();
  final inProgress = features.where((f) => f.status == 'in-progress').toList();
  final completed = features
      .where((f) => f.status == 'completed' || f.status == 'done')
      .toList();

  void printGroup(String label, String icon, List tasks) {
    if (tasks.isEmpty) return;
    print(label);
    for (final task in tasks) {
      print('  $icon [${task.id}] ${task.title}');
      if (task.description.isNotEmpty) print('    ${task.description}');
      if (task.files.isNotEmpty) print('    Files: ${task.files.join(", ")}');
    }
    print('');
  }

  printGroup('IN-PROGRESS', '◐', inProgress);
  printGroup('TODO', 'ā–”', todo);
  if (showAll) printGroup('COMPLETED', 'āœ…', completed);

  final archivedCount = ContextService.loadAllFeatures().length - features.length;
  if (!showAll && archivedCount > 0) {
    print('($archivedCount completed — run with --all to show)');
  }
}