execute method

  1. @override
Future<void> execute()
override

execute command

Implementation

@override
Future<void> execute() async {
  var name = p.basenameWithoutExtension(withArgument).pascalCase;
  if (withArgument.isEmpty) {
    // final dialog = CLI_Dialog(questions: [
    //   [LocaleKeys.ask_model_name.tr, 'name']
    // ]);
    // var result = dialog.ask()['name'] as String;
    var result = ask(LocaleKeys.ask_model_name.tr);
    name = result.pascalCase;
  }

  FileModel newFileModel;
  final classGenerator = ModelGenerator(
      name, containsArg('--private'), containsArg('--withCopy'));

  newFileModel = Structure.model(name, 'model', false, on: onCommand);

  var dartCode = classGenerator.generateDartClasses(await _jsonRawData);

  var modelPath = '${newFileModel.path}_model.dart';

  var model = writeFile(modelPath, dartCode.result, overwrite: true);

  for (var warning in dartCode.warnings) {
    LogService.info('warning: ${warning.path} ${warning.warning} ');
  }
  if (!containsArg('--skipProvider')) {
    var pathSplit = Structure.safeSplitPath(modelPath);
    pathSplit.removeWhere((element) => element == '.' || element == 'lib');
    handleFileCreate(
      name,
      'provider',
      onCommand,
      true,
      ProviderSample(
        name,
        createEndpoints: true,
        modelPath: Structure.pathToDirImport(model.path),
      ),
      'providers',
    );
  }
}