code: def validate_kwargs(
      single_stage: bool = False, fname: Optional[str] = None, **kwargs
  ) -> Dict[str, Any]:
      """Prepare, validate and process kwargs passed from cli"""
      cmd = kwargs.get("cmd")
      if not cmd and not single_stage:
          raise InvalidArgumentError("command is not specified")
  
      stage_name = kwargs.get("name")
      if stage_name and single_stage:
          raise InvalidArgumentError(
              "`-n|--name` is incompatible with `--single-stage`"
          )
      if stage_name and fname:
          raise InvalidArgumentError(
              "`--file` is currently incompatible with `-n|--name` "
              "and requires `--single-stage`"
          )
      if not stage_name and not single_stage:
          raise InvalidArgumentError("`-n|--name` is required")
  
      if single_stage:
          kwargs.pop("name", None)
  
      return kwargs
  
imports: import os
  import pathlib
  from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
  from funcy import concat, first, lsplit, rpartial
  from dvc.annotations import ANNOTATION_FIELDS
  from dvc.exceptions import InvalidArgumentError
  from dvc_data.hashfile.meta import Meta
  from .exceptions import MissingDataSource, StageExternalOutputsError, StagePathNotDirectoryError, StagePathNotFoundError, StagePathOutsideError
label_desc: Use image node_id 16 for calling a global function with example usage: validate_kwargs(single_stage, fname) and returns: kwargs