code: def add_args(
      parser: ArgumentParser,
      description: ArgsDescription,
      depth: int = 0,
  ) -> None:
      """
      Populate the given parser with arguments, as specified by the
      description. The description is a list of Arg, Cmd, and Group objects.
      """
      subparsers = None
      help_parser = None
  
      def description_sort_key(desc: Any) -> str:
          if isinstance(desc, Cmd):
              return desc.name
  
          # `sorted` is stable, so we shouldn't change the relative
          # positioning of non-Cmd arg descriptions.
          return ""
  
      # Sort descriptions alphabetically by name before passing them to
      # argparse. This ensures that `help` output is sorted
      # alphabetically.
      description = sorted(description, key=description_sort_key)
  
      for thing in description:
          if isinstance(thing, Cmd):
              if subparsers is None:
                  metavar = "sub" * depth + "command"
                  subparsers = parser.add_subparsers(metavar=metavar)
  
                  # If there are any subcommands at all, also add a `help`
                  # subcommand.
                  help_parser = subparsers.add_parser(
                      "help", help="show help for this command"
                  )
                  help_parser.set_defaults(func=help_func(parser))
  
              main_name, aliases = generate_aliases(thing.name)
  
              subparser_kwargs = {
                  "aliases": aliases,
                  "formatter_class": ArgumentDefaultsHelpFormatter,
              }
              if thing.help_str != SUPPRESS:
                  if thing.deprecation_message:
                      thing.help_str += " " + deprecation_warning(
                          thing.deprecation_message, color=False
                      )
                  subparser_kwargs["help"] = thing.help_str
              subparser = subparsers.add_parser(
                  main_name, **subparser_kwargs
              )
  
              subparser.set_defaults(func=thing.func)
              subparser.set_defaults(
                  **{("_" + "sub" * depth + "command"): thing.name}
              )
  
              # If this is the default subcommand, make calling the parent with
              # no subcommand behave the same as calling this subcommand with no
              # arguments.
              if thing.is_default:
                  thing.func = cast(Callable, thing.func)
                  parser.set_defaults(
                      func=wrap_func(subparser, thing.func)
                  )
  
              add_args(subparser, thing.subs, depth + 1)
  
          elif isinstance(thing, Arg):
              arg = parser.add_argument(*thing.args, **thing.kwargs)
              arg.completer = thing.completer  # type: ignore
  
          elif isinstance(thing, Group):
              group = parser.add_mutually_exclusive_group(
                  **thing.kwargs
              )
              for option in thing.options:
                  group.add_argument(*option.args, **option.kwargs)
  
          elif isinstance(thing, ArgGroup):
              arg_group = parser.add_argument_group(
                  thing.title, thing.description
              )
              for child_arg in thing.child_args:
                  arg_group.add_argument(
                      *child_arg.args, **child_arg.kwargs
                  )
  
          elif isinstance(thing, BoolOptArg):
              parser.add_argument(
                  thing.true_name,
                  dest=thing.dest,
                  action="store_true",
                  help=thing.true_help,
                  default=thing.default,
              )
              parser.add_argument(
                  thing.false_name,
                  dest=thing.dest,
                  action="store_false",
                  help=thing.false_help,
                  default=SUPPRESS,
              )
  
      # If there are any subcommands but none claimed the default action, make
      # the default print help.
      if subparsers is not None and parser.get_default("func") is None:
          parser.set_defaults(func=help_func(parser))
  
imports: import functools
  import itertools
  from argparse import SUPPRESS, ArgumentDefaultsHelpFormatter, ArgumentParser, Namespace
  from typing import Any, Callable, List, NamedTuple, Optional, Tuple, Union, cast
  from termcolor import colored
  from determined.common import util
label_desc: Use image node_id 6 for calling a global function with example usage: add_args(parser, description, depth) and returns: str, desc