oto/lib/cli/commands/command_exe.dart
2023-11-05 21:24:28 +09:00

60 lines
1.6 KiB
Dart

import 'dart:async';
import 'dart:io';
import 'package:oto_cli/cli/cli.dart';
import 'package:oto_cli/cli/commands/command_base.dart';
import 'package:dart_framework/utils/system_util.dart';
import 'package:oto_cli/oto/application.dart';
class CommandExe extends CommandBase {
@override
Map<String, List<String>> get arguments => {
'-j': ["Used when it's a Jenkins build."],
'-t': ["This is the setup for testing."],
'-f {file path}': ["Run the yaml file to process."]
};
@override
String get name => 'exe';
@override
Future execute(List<String> parameters) {
for (var i = 0; i < parameters.length; ++i) {
var item = parameters[i];
if (item.startsWith('-j')) {
Application.instance.build(BuildType.jenkins);
break;
}
if (item.startsWith('-t')) {
Application.instance.build(BuildType.test);
}
if (item.startsWith('-f')) {
var file = '';
if (parameters.length > i + 1) {
file = parameters[i + 1];
} else {
file = item.replaceFirst('-f', '').trimLeft();
}
startYaml(file);
break;
}
}
return simpleFuture;
}
void startYaml(String target) {
var file = File(target);
if (file.existsSync()) {
Application.instance
.build(BuildType.file, yamlContent: file.readAsStringSync());
} else {
CLI.print([
CLI.style('There are no files in path "$target"', color: Color.red)
]);
}
}
@override
String getDescription() {
return ':::: Read documents written in yaml to do process task.';
}
}