55 lines
1.7 KiB
Dart
55 lines
1.7 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
import 'package:dart_framework/platform/process.dart';
|
|
import 'package:oto_cli/oto/application.dart';
|
|
import 'package:oto_cli/oto/commands/command.dart';
|
|
import 'package:oto_cli/oto/data/command_data.dart';
|
|
|
|
class Shell extends Command {
|
|
@override
|
|
Future execute(DataCommand command) async {
|
|
var data = DataShell.fromJson(getParam(command));
|
|
var shell = StringBuffer(getCDPath(workspace));
|
|
var commands = data.commands;
|
|
for (var item in commands) {
|
|
shell.write(' && $item');
|
|
}
|
|
|
|
if(data.setMessage == null) {
|
|
var process = await ProcessExecutor.start(shell, logHandler: Application.logWithType);
|
|
return await completeProcess(process, command);
|
|
} else {
|
|
var process = await ProcessExecutor.run(shell, logHandler: Application.logWithType);
|
|
var str = process.stdout.toString();
|
|
var length = str.length;
|
|
str = str.substring(0, length - 1);
|
|
await setProperty(data.setMessage!, str);
|
|
return await complete(process.exitCode, command);
|
|
}
|
|
}
|
|
}
|
|
|
|
class ShellFile extends Command {
|
|
@override
|
|
Future execute(DataCommand command) async {
|
|
var data = DataShellFile.fromJson(getParam(command));
|
|
var path = Command.getPathNormal(data.path);
|
|
var shell = StringBuffer();
|
|
if (Platform.isWindows) {
|
|
shell.writeln('call $path');
|
|
} else {
|
|
shell.writeln('source $path');
|
|
}
|
|
var process = await ProcessExecutor.start(shell, logHandler: Application.logWithType);
|
|
|
|
return await completeProcess(process, command);
|
|
}
|
|
|
|
bool isSuccess(int exitCode) {
|
|
var success = false;
|
|
if (exitCode == 0 || exitCode == 128) {
|
|
success = true;
|
|
}
|
|
return success;
|
|
}
|
|
}
|