exec method

  1. @override
Future<void> exec(
  1. ExecContext context
)
override

Run command.

The contents of katana.yaml and the arguments of the command are passed to context.

コマンドを実行します。

contextkatana.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 form 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()}AddPageQuery,
/// )
/// class TestPage extends PageScopedWidget {
/// }
/// ```
typedef ${path.split("/").distinct().join("_").toPascalCase()}AddPageQuery = _\$${path.split("/").distinct().join("_").toPascalCase()}AddPageQuery;

/// [RouteQueryBuilder], which is also available externally.
///
/// ```dart
/// @PagePath(
///   "test",
///   implementType: ${path.split("/").distinct().join("_").toPascalCase()}EditPageQuery,
/// )
/// class TestPage extends PageScopedWidget {
/// }
/// ```
typedef ${path.split("/").distinct().join("_").toPascalCase()}EditPageQuery = _\$${path.split("/").distinct().join("_").toPascalCase()}EditPageQuery;
""";
      }
    },
  );
}