run method

  1. @override
void run()
override

Runs this command.

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

Implementation

@override
void run() {
  if (argResults!.rest.isEmpty) {
    print("❌ Please provide a service name.");
    return;
  }

  final service = argResults!.rest.first;

 // final bool http = argResults!["http"] as bool;
  final bool dio = argResults!["dio"] as bool;
  final bool retrofit = argResults!["retrofit"] as bool;

  String templatePath;

  // API services
  if (service == "api") {
    if (dio) {
      templatePath = "templates/service/api_dio.json";
    } else if (retrofit) {
      templatePath = "templates/service/api_retrofit.json";
    } else {
      templatePath = "templates/service/api_http.json";
    }
  }
  // Other services
  else {
    templatePath = "templates/service/$service.json";
  }

  final resolvedPath = PathHelper.template(templatePath);
  final template = JsonLoader.load(resolvedPath);

  Generator.generate(template, {
    "service": service,
  });

  print("✨ Service $service generated");
}