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 features tracked yet.\nRun: contextforge feature add'
        : 'No active features. Run: contextforge feature list --all to see completed.');
    return;
  }

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

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

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

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

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