import 'package:dart_framework/utils/system_util.dart';
import 'package:oto/oto/application.dart';
import 'package:oto/oto/commands/command.dart';
import 'package:oto/oto/data/command_data.dart';

class Gradle extends Command {
  @override
  Future execute(DataCommand command) async {
    DataGradle data = DataGradle.fromJson(getParam(command));
    List<String> args = data.args;

    StringBuffer shell = StringBuffer(getCDPath(workspace));
    shell.write(' $and gradle');

    for (String arg in args) {
      shell.write(' $arg');
    }
    var process =
        await runtime.start(shell, logHandler: Application.logWithType);

    return await completeProcess(process, command);
  }
}

void registerGradleCommand() {
  Command.register(
    CommandType.Gradle,
    () => Gradle(),
    spec: const CommandSpec(
      type: CommandType.Gradle,
      category: 'gradle',
      dataModel: 'DataGradle',
      samplePath: 'assets/yaml/sample/17_gradle.yaml',
    ),
  );
}
