execute method
Executes the Shorebird command and returns the result.
This method implements the standard service execution flow:
- Validate the configuration and service requirements
- Build the command string
- Execute the command
- Process and return the result
Returns:
- A ShorebirdResult containing the execution outcome
Throws:
- ShorebirdExecutionError: If command execution fails
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,
);
}
}
}