code: def parse_subcommands(parser, subcommands, argv):
      
  
      subparsers = parser.add_subparsers(dest='subparser_name')
  
      # add help sub-command
      parser_help = subparsers.add_parser(
          'help', help='Detailed help for actions using `help <action>`')
      parser_help.add_argument('action', nargs=1)
  
      # add all other subcommands
      modules = [
          name for _, name, _ in pkgutil.iter_modules(subcommands.__path__)]
      commands = [m for m in modules if m in argv]
  
      actions = {}
  
      # `commands` will contain the module corresponding to a single
      # subcommand if provided; otherwise, generate top-level help
      # message from all submodules in `modules`.
      for name in commands or modules:
          # set up subcommand help text. The first line of the dosctring
          # in the module is displayed as the help text in the
          # script-level help message (`script -h`). The entire
          # docstring is displayed in the help message for the
          # individual subcommand ((`script action -h`))
          # if no individual subcommand is specified (run_action[False]),
          # a full list of docstrings is displayed
          try:
              imp = '{}.{}'.format(subcommands.__name__, name)
              mod = importlib.import_module(imp)
          except Exception as e:
              log.error(e)
              continue
  
          subparser = subparsers.add_parser(
              name,
              help=mod.__doc__.lstrip().split('\n', 1)[0],
              description=mod.__doc__,
              formatter_class=argparse.RawDescriptionHelpFormatter)
  
          mod.build_parser(subparser)
  
          # see global subcommands/__init__.py
          subcommands.build_parser(subparser)
  
          actions[name] = mod.action
  
      return parser, actions
docs: Setup all sub-commands