resolveNext method

CommandContext<OptionDefinition, T> resolveNext(
  1. ArgParseResult<OptionDefinition> argParseResult,
  2. Map<String, String>? env,
  3. ContextProvider provider,
  4. CommandContext<OptionDefinition, T>? prevContext, {
  5. required CommandRunMode runMode,
})

Implementation

CommandContext<OptionDefinition, T> resolveNext(
  final ArgParseResult<OptionDefinition> argParseResult,
  final Map<String, String>? env,
  final ContextProvider provider,
  final CommandContext<OptionDefinition, T>? prevContext, {
  required final CommandRunMode runMode,
}) {
  final command = argParseResult.command;
  if (command == null) throw StateError('ArgParseResult.command is null');
  if (command is! AbstractCommand<OptionDefinition, T>) {
    throw StateError(
      'ArgParseResult.command is not an AbstractCommand: ${command.runtimeType}',
    );
  }

  final context = command.resolveCmd(
    argParseResult,
    env,
    provider,
    prevContext,
    runMode: runMode,
  );

  if (argParseResult.child case final ArgParseResult child) {
    final nextContext = resolveNext(
      child,
      env,
      provider,
      context,
      runMode: runMode,
    );
    context.next = nextContext;
  } else {
    context.next = null;
  }

  return context;
}