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 app = context.yaml.getAsMap("app");
  if (app.isEmpty) {
    error("The item [app] is missing. Please add an item.");
    return;
  }
  final info = app.getAsMap("info");
  if (info.isEmpty) {
    error("The item [app]->[info] is missing. Please add an item.");
    return;
  }
  final locale = info.getAsMap("locale").map(
        (key, value) => MapEntry(
          key,
          (value as Map).map(
            (k, v) => MapEntry(k.toString(), v.toString()),
          ),
        ),
      );
  if (locale.isEmpty) {
    error("The item [app]->[info]->[locale] is missing. Please add an item.");
    return;
  }
  final domain = info.get("domain", "");
  String? defaultLocale;
  final data = <String, Map<String, String>>{};
  for (final entry in locale.entries) {
    defaultLocale ??= entry.key;
    data[entry.key] = entry.value;
  }
  await AppInfo.apply(
    data: data,
    domain: domain,
    defaultLocale: defaultLocale,
  );
}