register method

void register(
  1. StandardCommand command, {
  2. required String ownerApp,
  3. String version = '0.1.0',
})

Register a command under (ownerApp, command.name).

Throws CommandAlreadyRegistered if a command with the same key already exists — this is the FR-009 namespacing rule: two apps registering the same command name coexist (different ownerApp), but the same app registering the same command name twice is a bug and is rejected.

Implementation

void register(
  StandardCommand command, {
  required String ownerApp,
  String version = '0.1.0',
}) {
  final key = RegistryKey(ownerApp, command.name);
  if (_commands.containsKey(key)) {
    throw CommandAlreadyRegistered(
      key,
      existingVersion: _commands[key]!.version,
    );
  }
  _commands[key] = RegisteredCommand(
    command: command,
    ownerApp: ownerApp,
    version: version,
  );
}