oto/lib/cli/commands/command_base.dart
toki c344fff3ec feat: command catalog 구조 refactor 및 문서화 완료
- lib/cli/commands/command_catalog.dart 추가: CLI 명령어 카탈로그 시스템 구현
- lib/oto/commands/command_catalog.dart 추가: OTO command catalog 구현
- test/oto_catalog_cli_test.dart 추가: 카탈로그 테스트 케이스
- CLI 명령어 라우팅 및 자동 생성 파이프라인 구축
- README.md, ROADMAP.md, current.md 업데이트
- milestone 문서들 (cli-automation-baseline, structured-automation-surface) 업데이트
2026-05-21 22:37:50 +09:00

92 lines
2.5 KiB
Dart

import 'dart:async';
import 'package:oto/cli/cli.dart';
enum PrintType { error, warning, information }
abstract class CommandBase {
Map<String, List<String>> get arguments => {};
String get name;
String get usage => '';
Future execute(List<String> parameters);
bool shouldPrintExecuteLog(List<String> parameters) => true;
bool shouldExecuteWithoutParameters() => false;
String getCommandDescription() {
return ' $name'.padRight(CLI.commandNameSpace) + getDescription();
}
String getDescription();
//==================== print ======================
final messageTypeMap = {
PrintType.error: {"color": Color.red, "message": "Error:"},
PrintType.warning: {"color": Color.yellow, "message": "Warning:"},
PrintType.information: {"color": Color.green, "message": "Information:"}
};
void printOut(String message, PrintType type) {
var color = messageTypeMap[type]!["color"]! as Color;
var typeStr = messageTypeMap[type]!["message"]! as String;
message = '${CLI.style(typeStr, background: color)} $message';
if (type == PrintType.error) {
printHelp(append: [message]);
} else {
CLI.print([message]);
}
}
void printWarning(String message) {
printHelp(append: [
'${CLI.style('Warning:', background: Color.yellow)} $message'
]);
}
void printInfo(String message) {
printHelp(
append: ['${CLI.style('Error:', background: Color.blue)} $message']);
}
void printHelp({List<String>? append}) {
var exeName = CLI.executableFileName;
final argumentTag = '{ARGUMENTS}';
final argumentDesc = arguments.isEmpty ? '' : '[arguments]';
var list = [
'',
getDescription(),
'',
'Usage: ${CLI.style('$exeName $name $usage', color: Color.greenStrong)}$argumentDesc',
argumentTag,
];
var index = list.indexOf(argumentTag);
list.removeAt(index);
if (arguments.isNotEmpty) {
List<String> argsDescs = ['', 'Available arguments:'];
for (var item in arguments.entries) {
var addedArg = false;
for (var argDesc in item.value) {
if (!addedArg) {
argDesc = ' ${item.key}'.padRight(CLI.commandNameSpace) + argDesc;
addedArg = true;
} else {
argDesc = ' '.padRight(CLI.commandNameSpace) + argDesc;
}
argsDescs.add(argDesc);
}
}
argsDescs.add('');
list.insertAll(index, argsDescs);
}
if (append != null) {
list.insertAll(0, append);
list.insert(0, '');
}
CLI.print(list);
}
}