Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions cloudinary_cli/modules/upload_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,29 @@
@option("-f", "--folder", default="",
help="The Cloudinary folder where you want to upload the assets. "
"You can specify a whole path, for example folder1/folder2/folder3. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@const-cloudinary - Suggest changing this help text to:

The path where you want to upload the assets. The path you specify will be pre-pended to the public IDs of the uploaded assets. You can specify a whole path, for example path1/path2/path3.

"Any folders that do not exist are automatically created.")
"If your product environment uses fixed folder mode, then any folders that do not exist are automatically created.")
@option("-p", "--preset", help="The upload preset to use.")
@option("-e", "--exclude-dir-name", is_flag=True, default=False,
help="Don't include the selected parent directory name in the public ID path of the uploaded files."
"This ensures that the public ID paths of the uploaded assets will be directly under the specified --(f)older, avoiding an extraneous level in the path."
"When this option is used, the contents of the parent directory are uploaded instead of the parent directory itself and thus the name of the specified parent directory is not included in the pubic ID path of the uploaded assets.")
@option("-w", "--concurrent_workers", type=int, default=30, help="Specify the number of concurrent network threads.")
def upload_dir(directory, glob_pattern, include_hidden, optional_parameter, optional_parameter_parsed, transformation,
folder, preset, concurrent_workers):
folder, preset, concurrent_workers, exclude_dir_name):
items, skipped = {}, {}

dir_to_upload = Path(path_join(getcwd(), directory))
if not dir_to_upload.exists():
logger.error(f"Directory: {dir_to_upload} does not exist")
return False

logger.info(f"Uploading directory '{dir_to_upload}'")
parent = dirname(dir_to_upload)
if exclude_dir_name:
logger.info(f"Uploading contents of directory '{dir_to_upload}'")
parent = dir_to_upload
else:
logger.info(f"Uploading directory '{dir_to_upload}'")
parent = dirname(dir_to_upload)

options = {
**{k: v for k, v in optional_parameter},
**{k: parse_option_value(v) for k, v in optional_parameter_parsed},
Expand Down
15 changes: 15 additions & 0 deletions test/test_modules/test_cli_upload_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ def test_cli_upload_dir_glob(self):

self.assertEqual(0, result.exit_code)
self.assertIn("11 resources uploaded", result.output)

def test_upload_dir_without_exclude_dir_name_option(self):
result = self.runner.invoke(cli, ["upload_dir", TEST_FILES_DIR, "-f", self.CLD_UPLOAD_DIR])

self.assertEqual(0, result.exit_code)
self.assertIn("12 resources uploaded", result.output)
self.assertIn("as " + self.CLD_UPLOAD_DIR + "/test_sync/", result.output)

def test_upload_dir_with_exclude_dir_name_option(self):
result = self.runner.invoke(cli, ["upload_dir", TEST_FILES_DIR, "-e", "-f", self.CLD_UPLOAD_DIR])

self.assertEqual(0, result.exit_code)
self.assertIn("12 resources uploaded", result.output)
self.assertIn("as " + self.CLD_UPLOAD_DIR, result.output)
self.assertNotIn("as " + self.CLD_UPLOAD_DIR + "/test_sync/", result.output)