Executor constructor

Executor(
  1. String name,
  2. String shortDescription,
  3. String version,
  4. List<Command> commands, {
  5. String? longDescription,
  6. List<AccessorListOption>? accessors,
  7. List<Flag<Object?>>? flags,
  8. List<Option<Object?>>? options,
  9. List<String>? defaultCommandPath,
  10. MambaContext? context,
  11. HelpFormatter? helpFormatter,
})

Implementation

new(
  this.name,
  this.shortDescription,
  String version,
  List<Command> commands, {
  this.longDescription,
  List<AccessorListOption>? accessors,
  List<Flag<Object?>>? flags,
  List<Option<Object?>>? options,
  List<String>? defaultCommandPath,
  this.context,
  this.helpFormatter,
}) : _version = _validateVersion(version),
     commands = List.unmodifiable(commands),
     accessors = List.unmodifiable(accessors ?? const []),
     flags = List.unmodifiable(flags ?? const []),
     options = List.unmodifiable(options ?? const []),
     defaultCommandPath = defaultCommandPath == null
         ? null
         : List.unmodifiable(defaultCommandPath) {
  final placements = HashSet<Command>.identity();
  void visit(Iterable<Command> children) {
    for (final command in children) {
      if (!placements.add(command)) {
        throw MambaRegistryError(
          'Command instance ${command.name} occupies more than one path.',
        );
      }
      if (_owners[command] != null) {
        throw MambaRegistryError(
          'Command instance ${command.name} already belongs to a configured Executor.',
        );
      }
      if (command is GroupCommand) visit(command.commands);
    }
  }

  visit(this.commands);
  // Validate everything before claiming any identity or binding metadata.
  _execution = _Execution(this);
  for (final command in placements) {
    _owners[command] = this;
  }
  _execution.bindMetadata();
}