in lib/src/list_tree.dart [108:168]
static void _addGlob(String root, List<SequenceNode> components,
Map<String, _ListTreeNode> trees) {
// The first [parent] represents the root directory itself. It may be null
// here if this is the first option with this particular [root]. If so,
// we'll create it below.
//
// As we iterate through [components], [parent] will be set to
// progressively more nested nodes.
var parent = trees[root];
for (var i = 0; i < components.length; i++) {
var component = components[i];
var recursive = component.nodes.any((node) => node is DoubleStarNode);
var complete = i == components.length - 1;
// If the parent node for this level of nesting already exists, the new
// option will be added to it as additional validator options and/or
// additional children.
//
// If the parent doesn't exist, we'll create it in one of the else
// clauses below.
if (parent != null) {
if (parent.isRecursive || recursive) {
// If [component] is recursive, mark [parent] as recursive. This
// will cause all of its children to be folded into its validator.
// If [parent] was already recursive, this is a no-op.
parent.makeRecursive();
// Add [component] and everything nested beneath it as an option to
// [parent]. Since [parent] is recursive, it will recursively list
// everything beneath it and filter them with one big glob.
parent.addOption(_join(components.sublist(i)));
return;
} else if (complete) {
// If [component] is the last component, add it to [parent]'s
// validator but not to its children.
parent.addOption(component);
} else {
// On the other hand if there are more components, add [component]
// to [parent]'s children and not its validator. Since we process
// each option's components separately, the same component is never
// both a validator and a child.
var children = parent.children!;
if (!children.containsKey(component)) {
children[component] = _ListTreeNode();
}
parent = children[component];
}
} else if (recursive) {
trees[root] = _ListTreeNode.recursive(_join(components.sublist(i)));
return;
} else if (complete) {
trees[root] = _ListTreeNode()..addOption(component);
} else {
var rootNode = _ListTreeNode();
trees[root] = rootNode;
var rootChildren = rootNode.children!;
rootChildren[component] = _ListTreeNode();
parent = rootChildren[component];
}
}
}