code: def cd(
      path: Optional[Union[Tuple[str], str]], verify: bool = True
  ) -> None:
      """Change the current directory within the Lightning Cloud filesystem."""
      with Live(
          Spinner("point", text=Text("pending...", style="white")),
          transient=True,
      ) as live:
          root = "/"
  
          if isinstance(path, Tuple) and len(path) > 0:
              path = " ".join(path)
  
          # handle ~/
          if isinstance(path, str) and path.startswith(_HOME):
              path = "/" + path.replace(_HOME, "")
  
          # handle no path -> /
          if path is None or len(path) == 0:
              path = "/"
  
          if not os.path.exists(_LIGHTNING_CONNECTION_FOLDER):
              os.makedirs(_LIGHTNING_CONNECTION_FOLDER)
  
          if not os.path.exists(_CD_FILE):
              # Start from the root
              if path.startswith(".."):
                  root = _apply_double_dots(root, path)
  
              with open(_CD_FILE, "w") as f:
                  f.write(root + "\n")
  
              live.stop()
  
              print(f"cd {root}")
  
              return root
  
          # read from saved cd
          with open(_CD_FILE) as f:
              lines = f.readlines()
              root = lines[0].replace("\n", "")
  
          if verify:
              if path.startswith("/"):
                  paths = [
                      os.path.join(path, p)
                      for p in ls.ls(path, print=False, use_live=False)
                  ]
              else:
                  paths = [
                      os.path.join(root, p)
                      for p in ls.ls(root, print=False, use_live=False)
                  ]
  
          # generate new root
          if root == "/":
              if path == "/":
                  root = "/"
              elif not path.startswith(".."):
                  if not path.startswith("/"):
                      path = "/" + path
                  root = path
              else:
                  root = _apply_double_dots(root, path)
          else:
              if path.startswith(".."):
                  root = _apply_double_dots(root, path)
              elif path.startswith("~"):
                  root = path[2:]
              else:
                  root = os.path.join(root, path)
  
          if (
              verify
              and root != "/"
              and not any(
                  p.startswith(root) or root.startswith(p)
                  for p in paths
              )
          ):
              _error_and_exit(f"no such file or directory: {path}")
  
          os.remove(_CD_FILE)
  
          # store new root
          with open(_CD_FILE, "w") as f:
              f.write(root + "\n")
  
          live.stop()
  
          print(f"cd {root}")
  
      return root
  
file_path: pytorch-lightning/src/lightning/app/cli/commands/cd.py
imports: import os
  from typing import Optional, Tuple, Union
  import click
  from rich.live import Live
  from rich.spinner import Spinner
  from rich.text import Text
  from lightning.app.cli.commands import ls
  from lightning.app.cli.connect.app import _LIGHTNING_CONNECTION_FOLDER
  from lightning.app.utilities.app_helpers import Logger
  from lightning.app.utilities.cli_helpers import _error_and_exit
label_desc: Use image node_id 1 for calling a global function with example usage: cd(path, verify) and returns: root, root