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(3, "");
if (path.isEmpty) {
error(
"[path] is not specified. Please enter [path] according to the following command.\r\nkatana code tmp form [path]\r\n",
);
return;
}
final existsMain = File("lib/main.dart").existsSync();
label("Create a tab template in `$directory/$path.dart`.");
await generateDartCode(
"$directory/$path",
path,
filter: (value) {
if (existsMain) {
return value;
} else {
return """$value
/// [RouteQueryBuilder], which is also available externally.
///
/// ```dart
/// @PagePath(
/// "test",
/// implementType: ${path.split("/").distinct().join("_").toPascalCase()}PageQuery,
/// )
/// class TestPage extends PageScopedWidget {
/// }
/// ```
typedef ${path.split("/").distinct().join("_").toPascalCase()}PageQuery = _\$${path.split("/").distinct().join("_").toPascalCase()}PageQuery;
""";
}
},
);
}