resolveCommandPath method
Resolves command tokens while skipping values owned by applicable inputs.
Implementation
CommandResolution resolveCommandPath(
List<String> args, {
CommandRegistry Function(CommandRegistry)? defaultTarget,
}) {
var registry = this;
final path = <CommandRegistry>[];
final indices = <int>{};
for (var index = 0; index < args.length; index++) {
final token = args[index];
if (token == '--') break;
final next = index + 1 < args.length ? args[index + 1] : null;
final ownedLength =
registry.registeredInputTokenLength(token, next: next) ??
defaultTarget
?.call(registry)
.registeredInputTokenLength(token, next: next);
if (MambaBuiltInFlags.isControl(token)) break;
if (ownedLength != null) {
index += ownedLength - 1;
continue;
}
final child = registry.commandRegistries
.where(
(candidate) =>
candidate.name == token ||
candidate.commandAliases?.contains(token) == true,
)
.firstOrNull;
if (child != null) {
registry = child;
path.add(child);
indices.add(index);
continue;
}
if (path.isEmpty && token == name) {
throw MambaApplicationNameException(name);
}
}
return CommandResolution(
registry: registry,
path: List.unmodifiable(path.map((item) => item.name)),
tokenIndices: Set.unmodifiable(indices),
);
}