execute method

CLIResult execute(
  1. String command
)

Execute a command and return the result

Implementation

CLIResult execute(String command) {
  if (!kDebugMode) {
    return CLIResult.error('DevTools CLI is only available in debug mode');
  }

  // Add to history
  _history.add(command);
  if (_history.length > _maxHistory) {
    _history.removeAt(0);
  }

  final parts = command.trim().split(RegExp(r'\s+'));
  if (parts.isEmpty) {
    return CLIResult.error('Empty command');
  }

  final cmd = parts[0].toLowerCase();
  final args = parts.length > 1 ? parts.sublist(1) : <String>[];

  try {
    switch (cmd) {
      case 'help':
      case '?':
        return _help();
      case 'state':
        return _state(args);
      case 'pulse':
        return _pulse(args);
      case 'di':
        return _di(args);
      case 'events':
        return _events(args);
      case 'clear':
        return _clear(args);
      case 'history':
        return _showHistory();
      default:
        return CLIResult.error(
          'Unknown command: $cmd. Type "help" for available commands.',
        );
    }
  } catch (e) {
    return CLIResult.error('Error: $e');
  }
}