-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gagandeep Pratihar
committed
Oct 16, 2024
1 parent
8eb3045
commit 61f686f
Showing
7 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import List, Tuple, Any | ||
from click import command, argument, option | ||
|
||
@command("admin", | ||
short_help="Run any methods that can be called through the admin API.", | ||
help="""\b | ||
Run any methods that can be called through the admin API. | ||
Format: cld <cli options> admin <command options> <method> <method parameters> | ||
\te.g. cld admin resources max_results=10 tags=sample | ||
\t OR | ||
\t cld admin resources -o max_results 10 -o tags sample | ||
\t OR | ||
\t cld admin resources max_results=10 -o tags sample | ||
""") | ||
@argument("params", nargs=-1) | ||
@option("-o", "--optional_parameter", multiple=True, nargs=2, help="Pass optional parameters as raw strings.") | ||
@option("-O", "--optional_parameter_parsed", multiple=True, nargs=2, | ||
help="Pass optional parameters as interpreted strings.") | ||
@option("-A", "--auto_paginate", is_flag=True, help="Will auto paginate Admin API calls.", default=False) | ||
@option("-ff", "--filter_fields", multiple=True, help="Filter fields to return when using auto pagination.") | ||
@option("-F", "--force", is_flag=True, help="Skip confirmation when running --auto-paginate.") | ||
@option("-ls", "--ls", is_flag=True, help="List all available methods in the Admin API.") | ||
@option("--save", nargs=1, help="Save output to a file.") | ||
@option("-d", "--doc", is_flag=True, help="Open the Admin API reference in a browser.") | ||
def admin( | ||
params: Tuple[str, ...], | ||
optional_parameter: List[Tuple[str, str]], | ||
optional_parameter_parsed: List[Tuple[str, str]], | ||
auto_paginate: bool, | ||
force: bool, | ||
filter_fields: List[str], | ||
ls: bool, | ||
save: str, | ||
doc: bool | ||
) -> Any: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import cloudinary | ||
from typing import Optional, Any, Tuple | ||
from click import command, option | ||
|
||
@command("config", help="Display the current configuration, and manage additional configurations.") | ||
@option("-n", "--new", help="""\b Create and name a configuration from a Cloudinary account environment variable. | ||
e.g. cld config -n <NAME> <CLOUDINARY_URL>""", nargs=2) | ||
@option("-ls", "--ls", help="List all saved configurations.", is_flag=True) | ||
@option("-s", "--show", help="Show details of a specified configuration.", nargs=1) | ||
@option("-rm", "--rm", help="Delete a specified configuration.", nargs=1) | ||
@option("-url", "--from_url", | ||
help="Create a configuration from a Cloudinary account environment variable. " | ||
"The configuration name is the cloud name.", | ||
nargs=1) | ||
def config( | ||
new: Optional[Tuple[str, str]], | ||
ls: bool, | ||
show: Optional[str], | ||
rm: Optional[str], | ||
from_url: Optional[str] | ||
) -> Optional[Any]: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import List, Tuple, Any, Optional | ||
from click import command, argument, option | ||
|
||
@command("provisioning", | ||
short_help="Run any methods that can be called through the provisioning API.", | ||
help="""\b | ||
Run any methods that can be called through the provisioning API. | ||
Format: cld <cli options> provisioning <command options> <method> <method parameters> | ||
\te.g. cld provisioning sub_accounts | ||
""") | ||
@argument("params", nargs=-1) | ||
@option("-o", "--optional_parameter", multiple=True, nargs=2, help="Pass optional parameters as raw strings.") | ||
@option("-O", "--optional_parameter_parsed", multiple=True, nargs=2, | ||
help="Pass optional parameters as interpreted strings.") | ||
@option("-ls", "--ls", is_flag=True, help="List all available methods in the Provisioning API.") | ||
@option("--save", nargs=1, help="Save output to a file.") | ||
@option("-d", "--doc", is_flag=True, help="Open the Provisioning API reference in a browser.") | ||
def provisioning( | ||
params: Tuple[str, ...], | ||
optional_parameter: List[Tuple[str, str]], | ||
optional_parameter_parsed: List[Tuple[str, str]], | ||
ls: bool, | ||
save: Optional[str], | ||
doc: bool | ||
) -> Any: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from typing import List, Optional, Tuple, Any | ||
from click import command, argument, option, launch | ||
|
||
@command("search", | ||
short_help="Run the admin API search method.", | ||
help="""\b | ||
Run the admin API search method. | ||
Format: cld <cli options> search <command options> <Lucene query syntax string> | ||
e.g. cld search cat AND tags:kitten -s public_id desc -f context -f tags -n 10 | ||
""") | ||
@argument("query", nargs=-1) | ||
@option("-f", "--with_field", multiple=True, help="Specify which non-default asset attributes to include " | ||
"in the result as a comma separated list. ") | ||
@option("-fi", "--fields", multiple=True, help="Specify which asset attributes to include in the result " | ||
"(together with a subset of the default attributes) as a comma separated" | ||
" list. This overrides any value specified for with_field.") | ||
@option("-s", "--sort_by", nargs=2, help="Sort search results by (field, <asc|desc>).") | ||
@option("-a", "--aggregate", nargs=1, | ||
help="Specify the attribute for which an aggregation count should be calculated and returned.") | ||
@option("-n", "--max_results", nargs=1, default=10, | ||
help="The maximum number of results to return. Default: 10, maximum: 500.") | ||
@option("-c", "--next_cursor", nargs=1, help="Continue a search using an existing cursor.") | ||
@option("-A", "--auto_paginate", is_flag=True, help="Return all results. Will call Admin API multiple times.") | ||
@option("-F", "--force", is_flag=True, help="Skip confirmation when running --auto-paginate.") | ||
@option("-ff", "--filter_fields", multiple=True, help="Specify which attributes to show in the response. " | ||
"None of the others will be shown.") | ||
@option("-t", "--ttl", nargs=1, default=300, help="Set the Search URL TTL in seconds. Default: 300.") | ||
@option("-u", "--url", is_flag=True, help="Build a signed search URL.") | ||
@option("-sq", "--search-query", is_flag=True, help="Show the search request query.", hidden=True) | ||
@option("--json", nargs=1, help="Save JSON output to a file. Usage: --json <filename>") | ||
@option("--csv", nargs=1, help="Save CSV output to a file. Usage: --csv <filename>") | ||
@option("-d", "--doc", is_flag=True, help="Open Search API documentation page.") | ||
def search( | ||
query: Tuple[str, ...], | ||
with_field: List[str], | ||
fields: List[str], | ||
sort_by: Optional[Tuple[str, str]], | ||
aggregate: Optional[str], | ||
max_results: str, | ||
next_cursor: Optional[str], | ||
auto_paginate: bool, | ||
force: bool, | ||
filter_fields: List[str], | ||
ttl: str, | ||
url: bool, | ||
search_query: bool, | ||
json: Optional[str], | ||
csv: Optional[str], | ||
doc: bool | ||
) -> None: | ||
... | ||
|
||
def execute_single_request(expression: Any, fields_to_keep: Tuple[str, ...]) -> Any: | ||
... | ||
|
||
def handle_auto_pagination(res: Any, expression: Any, force: bool, fields_to_keep: Tuple[str, ...]) -> Any: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import List, Tuple, Any | ||
from click import command, argument, option, Choice, echo, launch | ||
|
||
@command("utils", help="Call Cloudinary utility methods.") | ||
@argument("params", nargs=-1) | ||
@option("-o", "--optional_parameter", multiple=True, nargs=2, help="Pass optional parameters as raw strings.") | ||
@option("-O", "--optional_parameter_parsed", multiple=True, nargs=2, | ||
help="Pass optional parameters as interpreted strings.") | ||
@option("-ls", "--ls", is_flag=True, help="List all available utility methods.") | ||
def utils( | ||
params: Tuple[str, ...], | ||
optional_parameter: List[Tuple[str, str]], | ||
optional_parameter_parsed: List[Tuple[str, str]], | ||
ls: bool | ||
) -> bool: | ||
... | ||
|
||
@command("url", help="Generate a Cloudinary URL, which you can optionally open in your browser.") | ||
@argument("public_id", required=True) | ||
@argument("transformation", default="") | ||
@option("-rt", "--resource_type", default="image", type=Choice(['image', 'video', 'raw']), help="The asset type") | ||
@option("-t", "--type", "delivery_type", default="upload", | ||
type=Choice([ | ||
'upload', 'private', 'public', 'authenticated', 'fetch', 'list', 'url2png', | ||
'sprite', 'text', 'multi', 'facebook', 'twitter', 'twitter_name', 'gravatar', | ||
'youtube', 'hulu', 'vimeo', 'animoto', 'worldstarhiphop', 'dailymotion' | ||
]), | ||
help="The delivery type.") | ||
@option("-o", "--open", 'open_in_browser', is_flag=True, help="Generate the derived asset and open it in your browser.") | ||
@option("-s", "--sign", is_flag=True, help="Generate a signed URL.", default=False) | ||
def url( | ||
public_id: str, | ||
transformation: str, | ||
resource_type: str, | ||
delivery_type: str, | ||
open_in_browser: bool, | ||
sign: bool | ||
) -> None: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
from typing import Tuple, List, Optional | ||
from click import argument, echo, option | ||
from cloudinary_cli.cli_group import cli | ||
|
||
@cli.command("make", short_help="Return template code for implementing the specified Cloudinary widget.", | ||
help="""\b | ||
Return template code for implementing the specified Cloudinary widget. | ||
e.g. cld make media library widget | ||
cld make python find all empty folders | ||
""") | ||
@argument("template", nargs=-1) | ||
@option("-ll", "--list-languages", is_flag=True, help="List available languages.") | ||
@option("-lt", "--list-templates", is_flag=True, help="List available templates.") | ||
def make( | ||
template: Tuple[str, ...], | ||
list_languages: bool, | ||
list_templates: bool | ||
) -> bool: | ||
... | ||
|
||
def _handle_language_and_template(language_and_template: Tuple[str, ...]) -> Tuple[str, List[str]]: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
from typing import List | ||
from click import command, argument, option | ||
|
||
@command("migrate", | ||
short_help="Migrate files using an existing auto-upload mapping and a file of URLs.", | ||
help="Migrate a list of external media files to Cloudinary. " | ||
"The URLs of the files to migrate are listed in a separate file and must all have the same prefix.") | ||
@argument("upload_mapping", type=str) | ||
@argument("file", type=str) | ||
@option("-d", "--delimiter", default="\n", help="The separator used between the URLs. Default: New line") | ||
@option("-v", "--verbose", is_flag=True) | ||
def migrate( | ||
upload_mapping: str, | ||
file: str, | ||
delimiter: str, | ||
verbose: bool | ||
) -> bool: | ||
... | ||
|