runCommand method

  1. @override
Future<void> runCommand(
  1. ArgResults topLevelResults
)
override

Runs the command specified by topLevelResults.

This is notionally a protected method. It may be overridden or called from subclasses, but it shouldn't be called externally.

It's useful to override this to handle global flags and/or wrap the entire command in a block. For example, you might handle the --verbose flag here to enable verbose logging before running the command.

This returns the return value of Command.run.

Implementation

@override
Future<void> runCommand(ArgResults topLevelResults) async {
  if (topLevelResults['version'] == true) {
    // ignore: avoid_print
    Log.stdout(schemaDartVersion);
    return;
  }

  if (topLevelResults['verbose'] == true) {
    Log.verbose = true;
  }

  if (topLevelResults['help'] != false) {
    return super.runCommand(topLevelResults);
  }

  if (topLevelResults['connection-string'] == null) {
    throw Exception('connection-string is required');
  }

  // if (topLevelResults['output-dir'] == null) {
  //   throw Exception('output-dir is required');
  // }

  final connectionString = topLevelResults['connection-string'] as String;
  final outputDirectory = Directory(topLevelResults['output-dir'] as String);

  // if (!outputDirectory.existsSync()) {
  //   throw Exception('The given output directory does not exist: ${outputDirectory.path}');
  // }

  final schema = topLevelResults['schema'];

  final listOfTables = topLevelResults['tables'];

  final converter = SchemaConverter(
    connectionString: connectionString,
    outputDirectory: outputDirectory,
    schemaName: schema,
    tableNames: listOfTables,
  );

  await converter.convert();
}