exec method
Run command.
The contents of katana.yaml and the arguments of the command are passed to context.
コマンドを実行します。
contextにkatana.yamlの内容やコマンドの引数が渡されます。
Implementation
@override
Future<void> exec(ExecContext context) async {
final path = context.args.get(2, "");
if (path.isEmpty) {
error(
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code stateless [path]\r\n\r\n([path] must be entered in snake_case; numbers and underscores cannot be used at the beginning or end of the path. Also, you can create directories by using /.)\r\n",
);
return;
}
if (!validateFilePath(path)) {
error(
"Invalid path: $path. Please enter a valid path according to the following command.\r\nkatana code stateless [path]\r\n",
);
return;
}
label("Create a StatelessWidget class in `$directory/$path.dart`.");
final parentPath = path.parentPath();
if (parentPath.isNotEmpty) {
final parentDir = Directory("$directory/$parentPath");
if (!parentDir.existsSync()) {
await parentDir.create(recursive: true);
}
final parentTestDir = Directory("$testDirectory/$parentPath");
if (!parentTestDir.existsSync()) {
await parentTestDir.create(recursive: true);
}
}
await generateDartCode("$directory/$path", path);
await generateDartTestCode("$testDirectory/$path", path);
}