62 lines
No EOL
1.9 KiB
Dart
62 lines
No EOL
1.9 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:oto_cli/cli/commands/command_base.dart';
|
|
import 'package:dart_framework/utils/system_util.dart';
|
|
import 'package:oto_cli/cli/commands/scheduler/scheduler_manager.dart';
|
|
|
|
class CommandScheduler extends CommandBase {
|
|
|
|
@override
|
|
Map<String, List<String>> get arguments => {
|
|
'-l': ["Shows the currently operational schedulers."],
|
|
'-r {file}': ["Register the defined file (yaml) with the scheduler."],
|
|
'-u {alias}': ["Unregister schedules registered with the scheduler based on alias."]
|
|
};
|
|
@override
|
|
String get name => 'scheduler';
|
|
final SchedulerManager _scheduler = SchedulerManager();
|
|
|
|
@override
|
|
Future execute(List<String> parameters) async {
|
|
for (var i = 0; i < parameters.length; ++i) {
|
|
var item = parameters[i];
|
|
if (item.startsWith('-l')) {
|
|
await _scheduler.showList();
|
|
break;
|
|
} else if (item.startsWith('-r')) {
|
|
var file = '';
|
|
if (parameters.length > i + 1) {
|
|
file = parameters[i + 1];
|
|
} else {
|
|
file = item.replaceFirst('-r', '').trimLeft();
|
|
}
|
|
await _scheduler.regist(file);
|
|
exit(0);
|
|
} else if (item.startsWith('-u')) {
|
|
var alias = '';
|
|
if (parameters.length > i + 1) {
|
|
alias = parameters[i + 1];
|
|
} else {
|
|
alias = item.replaceFirst('-u', '').trimLeft();
|
|
}
|
|
await _scheduler.unregist(alias);
|
|
break;
|
|
} else if (item.startsWith('-s')) { //hidden: start process
|
|
await _scheduler.start();
|
|
break;
|
|
} else if (item.startsWith('-t')) { //hidden: terminate process
|
|
await _scheduler.terminate();
|
|
break;
|
|
} else {
|
|
printHelp();
|
|
}
|
|
}
|
|
return simpleFuture;
|
|
}
|
|
|
|
@override
|
|
String getDescription() {
|
|
return ':::: Run as a service on the background.';
|
|
}
|
|
} |