execute method

Future<ShorebirdResult> execute()

Executes the Shorebird command and returns the result.

This method implements the standard service execution flow:

  1. Validate the configuration and service requirements
  2. Build the command string
  3. Execute the command
  4. Process and return the result

Returns:

Throws:

Implementation

Future<ShorebirdResult> execute() async {
  final startTime = DateTime.now();

  try {
    // Step 1: Validate configuration and requirements
    await validate();

    // Step 2: Build the command
    final command = buildCommand();
    logCommand(command);

    // Step 3: Execute the command
    final result = await _executeCommand(command, startTime);

    return result;
  } catch (error) {
    final duration = DateTime.now().difference(startTime);
    logError(
        'Service execution failed after ${duration.inMilliseconds}ms: $error');

    if (error is ShorebirdExecutionError) {
      rethrow;
    } else {
      throw ShorebirdExecutionError(
        message: 'Service execution failed: $error',
        command: 'shorebird service',
        commandOutput: error.toString(),
        processExitCode: 1,
        executionTime: duration,
      );
    }
  }
}