code: def cli():
      # type: () -> int
      title = "clearml-data - Dataset Management & Versioning CLI"
      print(title)
      parser = ArgumentParser(  # noqa
          description=title,
          prog="clearml-data",
          formatter_class=partial(
              HelpFormatter, indent_increment=0, max_help_position=10
          ),
      )
      subparsers = parser.add_subparsers(
          help="Dataset actions", dest="command"
      )
  
      create = subparsers.add_parser(
          "create", help="Create a new dataset"
      )
      create.add_argument(
          "--parents",
          type=str,
          nargs="*",
          help="[Optional] Specify dataset parents IDs (i.e. merge all parents). "
          "Example: a17b4fID1 f0ee5ID2 a17b4f09eID3",
      )
      create.add_argument(
          "--project",
          type=str,
          required=False,
          default=None,
          help="Dataset project name",
      )
      create.add_argument(
          "--name",
          type=str,
          required=True,
          default=None,
          help="Dataset name",
      )
      create.add_argument(
          "--version",
          type=str,
          required=False,
          default=None,
          help="Dataset version",
      )
      create.add_argument(
          "--output-uri",
          type=str,
          required=False,
          default=None,
          help="Output URI for files in this dataset (deprecated, use '--storage' instead)",
      )
      create.add_argument(
          "--storage",
          type=str,
          default=None,
          help="Remote storage to use for the dataset files (default: files_server). "
          "Examples: 's3://bucket/data', 'gs://bucket/data', 'azure://bucket/data', "
          "'/mnt/shared/folder/data'",
      )
      create.add_argument(
          "--tags", type=str, nargs="*", help="Dataset user Tags"
      )
      create.set_defaults(func=ds_create)
  
      add = subparsers.add_parser(
          "add", help="Add files or links to the dataset"
      )
      add.add_argument(
          "--id",
          type=str,
          required=False,
          help="Previously created dataset id. Default: previously created/accessed dataset",
      )
      add.add_argument(
          "--dataset-folder",
          type=str,
          default=None,
          help="Dataset base folder to add the files to (default: Dataset root)",
      )
      add.add_argument(
          "--files", type=str, nargs="*", help="Files / folders to add."
      )
      add.add_argument(
          "--wildcard",
          type=str,
          nargs="*",
          help="Add specific set of files, denoted by these wildcards. Multiple wildcards can be passed",
      )
      add.add_argument(
          "--links",
          type=str,
          nargs="*",
          help=(
              "Links to files / folders to add. Supports s3, gs, azure links. "
              "Example: s3://bucket/data azure://bucket/folder"
          ),
      )
      add.add_argument(
          "--non-recursive",
          action="store_true",
          default=False,
          help="Disable recursive scan of files",
      )
      add.add_argument(
          "--verbose",
          action="store_true",
          default=False,
          help="Verbose reporting",
      )
      add.add_argument(
          "--max-workers",
          type=int,
          default=None,
          help="Number of threads to add the files with. Defaults to the number of logical cores",
      )
      add.set_defaults(func=ds_add)
  
      set_description = subparsers.add_parser(
          "set-description", help="Set description to the dataset"
      )
      set_description.add_argument(
          "--description",
          type=str,
          required=True,
          help="Description of the dataset",
      )
      set_description.add_argument(
          "--id",
          type=str,
          required=False,
          help="Previously created dataset id. Default: previously created/accessed dataset",
      )
      set_description.set_defaults(func=ds_set_description)
  
      sync = subparsers.add_parser(
          "sync", help="Sync a local folder with the dataset"
      )
      sync.add_argument(
          "--id",
          type=str,
          required=False,
          help="Previously created dataset id. Default: previously created/accessed dataset",
      )
      sync.add_argument(
          "--dataset-folder",
          type=str,
          default=None,
          help="Dataset base folder to add the files to (default: Dataset root)",
      )
      sync.add_argument(
          "--folder",
          type=str,
          required=True,
          help="Local folder to sync (support for wildcard selection). "
          "Example: ~/data/*.jpg",
      )
      sync.add_argument(
          "--parents",
          type=str,
          nargs="*",
          help="[Optional] Specify dataset parents IDs (i.e. merge all parents). "
          "Example: a17b4fID1 f0ee5ID2 a17b4f09eID3",
      )
      sync.add_argument(
          "--project",
          type=str,
          required=False,
          default=None,
          help="[Optional] Dataset project name",
      )
      sync.add_argument(
          "--name",
          type=str,
          required=False,
          default=None,
          help="[Optional] Dataset project name",
      )
      sync.add_argument(
          "--version",
          type=str,
          required=False,
          default=None,
          help="[Optional] Dataset version",
      )
      sync.add_argument(
          "--output-uri",
          type=str,
          required=False,
          default=None,
          help="[Optional] Output URI for artifacts/debug samples. Useable when creating the dataset (deprecated, use '--storage' instead)",
      )
      sync.add_argument(
          "--tags",
          type=str,
          nargs="*",
          help="[Optional] Dataset user Tags",
      )
      sync.add_argument(
          "--storage",
          type=str,
          default=None,
          help="Remote storage to use for the dataset files (default: files_server). "
          "Examples: 's3://bucket/data', 'gs://bucket/data', 'azure://bucket/data', "
          "'/mnt/shared/folder/data'",
      )
      sync.add_argument(
          "--skip-close",
          action="store_true",
          default=False,
          help="Do not auto close dataset after syncing folders",
      )
      sync.add_argument(
          "--chunk-size",
          default=512,
          type=int,
          help="Set dataset artifact chunk size in MB. Default 512mb, (pass -1 for a single chunk). "
          "Example: 512, dataset will be split and uploaded in 512mb chunks.",
      )
      sync.add_argument(
          "--verbose",
          action="store_true",
          default=False,
          help="Verbose reporting",
      )
      sync.set_defaults(func=ds_sync)
  
      remove = subparsers.add_parser(
          "remove", help="Remove files/links from the dataset"
      )
      remove.add_argument(
          "--id",
          type=str,
          required=False,
          help="Previously created dataset id. Default: previously created/accessed dataset",
      )
      remove.add_argument(
          "--files",
          type=str,
          required=False,
          nargs="*",
          help="Files / folders to remove (support for wildcard selection). "
          "Notice: File path is the dataset path not the local path. "
          "Example: data/*.jpg data/jsons/",
      )
      remove.add_argument(
          "--non-recursive",
          action="store_true",
          default=False,
          help="Disable recursive scan of files",
      )
      remove.add_argument(
          "--verbose",
          action="store_true",
          default=False,
          help="Verbose reporting",
      )
      remove.set_defaults(func=ds_remove)
  
      upload = subparsers.add_parser(
          "upload",
          help="Upload the local dataset changes to the server",
      )
      upload.add_argument(
          "--id",
          type=str,
          required=False,
          help="Previously created dataset id. Default: previously created/accessed dataset",
      )
      upload.add_argument(
          "--storage",
          type=str,
          default=None,
          help="Remote storage to use for the dataset files (default: files_server). "
          "Examples: 's3://bucket/data', 'gs://bucket/data', 'azure://bucket/data', "
          "'/mnt/shared/folder/data'",
      )
      upload.add_argument(
          "--chunk-size",
          default=512,
          type=int,
          help="Set dataset artifact chunk size in MB. Default 512, (pass -1 for a single chunk). "
          "Example: 512, dataset will be split and uploaded in 512mb chunks.",
      )
      upload.add_argument(
          "--verbose",
          default=False,
          action="store_true",
          help="Verbose reporting",
      )
      upload.add_argument(
          "--max-workers",
          type=int,
          default=None,
          help="Number of threads to upload the files with. Defaults to 1 if uploading to a cloud provider ('s3', 'azure', 'gs') OR to the number of logical cores otherwise",
      )
      upload.set_defaults(func=ds_upload)
  
      finalize = subparsers.add_parser(
          "close",
          help="Finalize and close the dataset (implies auto upload)",
      )
      finalize.add_argument(
          "--id",
          type=str,
          required=False,
          help="Previously created dataset id. Default: previously created/accessed dataset",
      )
      finalize.add_argument(
          "--storage",
          type=str,
          default=None,
          help="Remote storage to use for the dataset files (default: files_server). "
          "Examples: 's3://bucket/data', 'gs://bucket/data', 'azure://bucket/data', "
          "'/mnt/shared/folder/data'",
      )
      finalize.add_argument(
          "--disable-upload",
          action="store_true",
          default=False,
          help="Disable automatic upload when closing the dataset",
      )
      finalize.add_argument(
          "--chunk-size",
          default=512,
          type=int,
          help="Set dataset artifact chunk size in MB. Default 512, (pass -1 for a single chunk). "
          "Example: 512, dataset will be split and uploaded in 512mb chunks.",
      )
      finalize.add_argument(
          "--verbose",
          action="store_true",
          default=False,
          help="Verbose reporting",
      )
      finalize.add_argument(
          "--max-workers",
          type=int,
          default=None,
          help="Number of threads to upload the files with. Defaults to 1 if uploading to a cloud provider ('s3', 'azure', 'gs') OR to the number of logical cores otherwise",
      )
      finalize.set_defaults(func=ds_close)
  
      publish = subparsers.add_parser(
          "publish", help="Publish dataset task"
      )
      publish.add_argument(
          "--id",
          type=str,
          required=True,
          help="The dataset task id to be published.",
      )
      publish.set_defaults(func=ds_publish)
  
      delete = subparsers.add_parser("delete", help="Delete a dataset")
      delete.add_argument(
          "--id",
          type=str,
          required=False,
          help="Previously created dataset id. Default: previously created/accessed dataset",
      )
      delete.add_argument(
          "--project",
          type=str,
          required=False,
          help="The project the dataset(s) to be deleted belong(s) to",
      )
      delete.add_argument(
          "--name",
          type=str,
          required=False,
          help="The name of the dataset(s) to be deleted",
      )
      delete.add_argument(
          "--version",
          type=str,
          required=False,
          help="The version of the dataset(s) to be deleted",
      )
      delete.add_argument(
          "--force",
          action="store_true",
          default=False,
          help="Force dataset deletion even if other dataset versions depend on it. Must also be used if entire-dataset flag is used",
      )
      delete.add_argument(
          "--entire-dataset",
          action="store_true",
          default=False,
          help="Delete all found datasets",
      )
      delete.set_defaults(func=ds_delete)
  
      rename = subparsers.add_parser("rename", help="Rename a dataset")
      rename.add_argument(
          "--new-name",
          type=str,
          required=True,
          help="The new name of the dataset(s)",
      )
      rename.add_argument(
          "--project",
          type=str,
          required=True,
          help="The project the dataset(s) to be renamed belong(s) to",
      )
      rename.add_argument(
          "--name",
          type=str,
          required=True,
          help="The name of the dataset(s) to be renamed",
      )
      rename.set_defaults(func=ds_rename)
  
      move = subparsers.add_parser(
          "move", help="Move a dataset to another project"
      )
      move.add_argument(
          "--new-project",
          type=str,
          required=True,
          help="The new project of the dataset(s)",
      )
      move.add_argument(
          "--project",
          type=str,
          required=True,
          help="The project the dataset(s) to be moved belong(s) to",
      )
      move.add_argument(
          "--name",
          type=str,
          required=True,
          help="The name of the dataset(s) to be moved",
      )
      move.set_defaults(func=ds_move)
  
      compare = subparsers.add_parser(
          "compare", help="Compare two datasets (target vs source)"
      )
      compare.add_argument(
          "--source",
          type=str,
          required=True,
          help="Source dataset id (used as baseline)",
      )
      compare.add_argument(
          "--target",
          type=str,
          required=True,
          help="Target dataset id (compare against the source baseline dataset)",
      )
      compare.add_argument(
          "--verbose",
          default=False,
          action="store_true",
          help="Verbose report all file changes (instead of summary)",
      )
      compare.set_defaults(func=ds_compare)
  
      squash = subparsers.add_parser(
          "squash",
          help="Squash multiple datasets into a single dataset version (merge down)",
      )
      squash.add_argument(
          "--name",
          type=str,
          required=True,
          help="Create squashed dataset name",
      )
      squash.add_argument(
          "--ids",
          type=str,
          required=True,
          nargs="*",
          help="Source dataset IDs to squash (merge down)",
      )
      squash.add_argument(
          "--storage",
          type=str,
          default=None,
          help="See `upload storage`",
      )
      squash.add_argument(
          "--verbose",
          default=False,
          action="store_true",
          help="Verbose report all file changes (instead of summary)",
      )
      squash.set_defaults(func=ds_squash)
  
      search = subparsers.add_parser(
          "search",
          help="Search datasets in the system (sorted by creation time)",
      )
      search.add_argument(
          "--ids",
          type=str,
          nargs="*",
          help="Specify list of dataset IDs",
      )
      search.add_argument(
          "--project", type=str, help="Specify datasets project name"
      )
      search.add_argument(
          "--name",
          type=str,
          help="Specify datasets partial name matching",
      )
      search.add_argument(
          "--tags",
          type=str,
          nargs="*",
          help="Specify list of dataset user tags",
      )
      search.add_argument(
          "--not-only-completed",
          action="store_true",
          default=False,
          help="If set, return datasets that are still in progress as well",
      )
      search.add_argument(
          "--non-recursive-project-search",
          action="store_true",
          default=False,
          help="Don't search inside subprojects",
      )
      search.set_defaults(func=ds_search)
  
      verify = subparsers.add_parser(
          "verify", help="Verify local dataset content"
      )
      verify.add_argument(
          "--id",
          type=str,
          required=False,
          help="Specify dataset id. Default: previously created/accessed dataset",
      )
      verify.add_argument(
          "--folder",
          type=str,
          help="Specify dataset local copy (if not provided the local cache folder will be verified)",
      )
      verify.add_argument(
          "--filesize",
          action="store_true",
          default=False,
          help="If True, only verify file size and skip hash checks (default: false)",
      )
      verify.add_argument(
          "--verbose",
          action="store_true",
          default=False,
          help="Verbose reporting",
      )
      verify.set_defaults(func=ds_verify)
  
      ls = subparsers.add_parser("list", help="List dataset content")
      ls.add_argument(
          "--id",
          type=str,
          required=False,
          help="Specify dataset id (or use project/name instead). Default: previously accessed dataset.",
      )
      ls.add_argument(
          "--project", type=str, help="Specify dataset project name"
      )
      ls.add_argument("--name", type=str, help="Specify dataset name")
      ls.add_argument(
          "--version",
          type=str,
          help="Specify dataset version",
          default=None,
      )
      ls.add_argument(
          "--filter",
          type=str,
          nargs="*",
          help="Filter files based on folder / wildcard, multiple filters are supported. "
          "Example: folder/date_*.json folder/sub-folder",
      )
      ls.add_argument(
          "--modified",
          action="store_true",
          default=False,
          help="Only list file changes (add/remove/modify) introduced in this version",
      )
      ls.set_defaults(func=ds_list)
  
      get = subparsers.add_parser(
          "get",
          help="Get a local copy of a dataset (default: read only cached folder)",
      )
      get.add_argument(
          "--id",
          type=str,
          required=False,
          help="Previously created dataset id. Default: previously created/accessed dataset",
      )
      get.add_argument(
          "--copy",
          type=str,
          default=None,
          help="Get a writable copy of the dataset to a specific output folder",
      )
      get.add_argument(
          "--link",
          type=str,
          default=None,
          help="Create a soft link (not supported on Windows) to a "
          "read-only cached folder containing the dataset",
      )
      get.add_argument(
          "--part",
          type=int,
          default=None,
          help="Retrieve a partial copy of the dataset. "
          "Part number (0 to `num-parts`-1) of total parts --num-parts.",
      )
      get.add_argument(
          "--num-parts",
          type=int,
          default=None,
          help="Total number of parts to divide the dataset to. "
          "Notice minimum retrieved part is a single chunk in a dataset (or its parents)."
          "Example: Dataset gen4, with 3 parents, each with a single chunk, "
          "can be divided into 4 parts",
      )
      get.add_argument(
          "--overwrite",
          action="store_true",
          default=False,
          help="If True, overwrite the target folder",
      )
      get.add_argument(
          "--verbose",
          action="store_true",
          default=False,
          help="Verbose reporting",
      )
      get.add_argument(
          "--max-workers",
          type=int,
          default=None,
          help="Number of threads to get the files with. Defaults to the number of logical cores",
      )
      get.set_defaults(func=ds_get)
  
      args = parser.parse_args()
      args = restore_state(args)
  
      if args.command:
          args.func(args)
      else:
          parser.print_help()
      return 0
  
imports: import json
  import os
  import shutil
  from argparse import ArgumentParser, HelpFormatter
  from functools import partial
  from typing import Sequence
  from pathlib2 import Path
  import clearml.backend_api.session
  from clearml.datasets import Dataset
  from clearml.version import __version__
label_desc: Use image node_id 5 for calling a global function with example usage: cli() and returns: int