resolveClientEnvFile method
Resolves the env file for client, failing with a helpful message
(including the list of known clients) when the client or file is missing.
Implementation
Future<File> resolveClientEnvFile(String client,
{bool isTest = false}) async {
if (client.trim().isEmpty ||
client.contains('/') ||
client.contains('\\') ||
client == '.' ||
client == '..') {
throw BuildException(
'Invalid client name "$client".',
fix: 'Client names must match a folder directly under "clients/".',
);
}
final clientDir = Directory(p.join(clientsDir.path, client));
if (!clientDir.existsSync()) {
final known = await listClientNames();
final hint = known.isEmpty
? 'No clients exist yet. Run "udara_cli setup --clients $client".'
: 'Available clients: ${known.join(', ')}. '
'Run "udara_cli setup --clients $client" to create it.';
throw BuildException('Client "$client" not found.', fix: hint);
}
final envFileName = isTest ? '.env_test' : '.env';
final envFile = File(p.join(clientDir.path, envFileName));
if (!envFile.existsSync()) {
throw BuildException(
'Environment file missing for client "$client": $envFileName',
fix: 'Create "${envFile.path}" or run '
'"udara_cli setup --clients $client" to generate a template.',
);
}
return envFile;
}