code: import os
  from argparse import Namespace, _SubParsersAction
  
  from llama_index import SimpleDirectoryReader
  
  from .configuration import load_index, save_index
  
  
  def add_cli(args: Namespace) -> None:
      """Handle subcommand "add"."""
      index = load_index()
  
      for p in args.files:
          if not os.path.exists(p):
              raise FileNotFoundError(p)
          if os.path.isdir(p):
              documents = SimpleDirectoryReader(p).load_data()
              for document in documents:
                  index.insert(document)
          else:
              documents = SimpleDirectoryReader(input_files=[p]).load_data()
              for document in documents:
                  index.insert(document)
  
      save_index(index)
  
  
  def register_add_cli(subparsers: _SubParsersAction) -> None:
      """Register subcommand "add" to ArgumentParser."""
      parser = subparsers.add_parser("add")
      parser.add_argument(
          "files",
          default=".",
          nargs="+",
          help="Files to add",
      )
  
      parser.set_defaults(func=add_cli)
  
apis: llama_index.SimpleDirectoryReader
extract_api: [((368, 384), 'os.path.isdir', 'os.path.isdir', (['p'], {}), '(p)\n', (381, 384), False, 'import os\n'), ((299, 316), 'os.path.exists', 'os.path.exists', (['p'], {}), '(p)\n', (313, 316), False, 'import os\n'), ((410, 434), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['p'], {}), '(p)\n', (431, 434), False, 'from llama_index import SimpleDirectoryReader\n'), ((563, 601), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', ([], {'input_files': '[p]'}), '(input_files=[p])\n', (584, 601), False, 'from llama_index import SimpleDirectoryReader\n')]