run method

  1. @override
Future<int> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<int> run() async
{
  final env = await loadEnv();
  if (env == null) {
    errorLn(
      'Failed to find the env.\nPlease, specify a valid env in your config.'
    );
    return resultError;
  }
  final executor = DatabaseExecutor(
    env: env,
    passwordProvider: () => getPassword(env.user),
  );
  try {
    await executor.drop();
    infoLn('The "${env.dbName}" database has been successfully dropped.');
    return resultOk;
  } on ConnectionException catch (e) {
    errorLn('Failed to connect: ${e.message}.');
    return resultError;
  } on DatabaseException catch (e) {
    errorLn('Failed to drop the database: ${e.message}.');
    return resultError;
  } catch (e) {
    errorLn('Failed to drop the database: $e.');
    return resultError;
  }
}