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 AwsCli extends Command {
  @override
  Future execute(DataCommand command) async {
    DataAwsCli data = DataAwsCli.fromJson(getParam(command));
    String subCommand = data.subCommand;
    List<String> args = data.args;

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

    return await completeProcess(process, command);
  }
}

void registerAwsCliCommand() {
  Command.register(
    CommandType.AwsCli,
    () => AwsCli(),
    spec: const CommandSpec(
      type: CommandType.AwsCli,
      category: 'aws',
      dataModel: 'DataAwsCli',
      samplePath: 'assets/yaml/sample/19_awscli.yaml',
    ),
  );
}
