code: def parser_add_version_opt(
      parser, mod_name, include_name=False, delay=False
  ):
      """Setup --version option
  
      Parameters
      ----------
      parser:
      mod_name: str, optional
      include_name: bool, optional
      delay: bool, optional
        If set to True, no action is taken immediately, and rather
        we assign the function which would print the version. Necessary for
        early pre-parsing of the cmdline
      """
  
      def print_version():
          mod = sys.modules.get(mod_name, None)
          version = getattr(mod, "__version__", None)
          if version is None:
              # Let's use the standard Python mechanism if underlying module
              # did not provide __version__
              try:
                  if sys.version_info < (3, 10):
                      import importlib_metadata as im
                  else:
                      import importlib.metadata as im
  
                  pkg = im.packages_distributions()[mod_name][0]
                  version = im.version(pkg)
              except Exception:
                  version = "unknown"
          if include_name:
              print("%s %s" % (mod_name, version))
          else:
              print(version)
          sys.exit(0)
  
      class versionAction(argparse.Action):
          def __call__(self, parser, args, values, option_string=None):
              if delay:
                  setattr(args, self.dest, print_version)
              else:
                  print_version()
  
      parser.add_argument(
          "--version",
          nargs=0,
          action=versionAction,
          help=(
              "show the program's version"
              if not mod_name
              else "show the module and its version which provides the command"
          ),
      )
  
imports: import argparse
  import logging
  import sys
  from collections import defaultdict
  from functools import partial
  from datalad import __version__
  from datalad.interface.base import get_cmd_doc, get_interface_groups, is_api_arg, load_interface
  from datalad.support.constraints import EnsureChoice
  from datalad.utils import getargspec
  from .common_args import common_args
  from .exec import call_from_parser
  from .helpers import get_commands_from_groups
  from .interface import alter_interface_docs_for_cmdline, get_cmd_ex, get_cmdline_command_name
label_desc: Use image node_id 11 for calling a global function with example usage: parser_add_version_opt(parser, mod_name, include_name, delay) without return types