commandContextOf<O extends OptionDefinition, T> function
The leaf CommandContext resolved for this completion, if the command runner prepared one.
Null when completion did not resolve the command line.
T is the command runner's result type. Omit the type arguments to
accept whatever result type was used.
Walk CommandContext.prev toward the root. Root options, including global options, are on CommandContext.root. The leaf command's own options are on the returned context.
Implementation
CommandContext<O, T>? commandContextOf<O extends OptionDefinition, T>(
final CompletionContext context,
) {
if (context is! CommandCompletionContext<T>) return null;
final leaf = context.leafContext;
if (leaf is CommandContext<O, T>) return leaf;
return null;
}