Skip to content

Commit 8ab1196

Browse files
Fix warnings and errors
1 parent 52c90a4 commit 8ab1196

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

cloudinary_cli/cli_group.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
CONTEXT_SETTINGS = dict(max_content_width=shutil.get_terminal_size()[0], terminal_width=shutil.get_terminal_size()[0])
1515

1616

17-
@click.group(context_settings=CONTEXT_SETTINGS)
17+
@click.group(context_settings=CONTEXT_SETTINGS, invoke_without_command=True)
1818
@click.help_option()
1919
@click.version_option(cli_version, prog_name="Cloudinary CLI",
2020
message=f"%(prog)s, version %(version)s\n"
@@ -24,10 +24,11 @@
2424
help="""Tell the CLI which account to run the command on by specifying an account environment variable."""
2525
)
2626
@click.option("-C", "--config_saved",
27-
help="""Tell the CLI which account to run the command on by specifying a saved configuration - see
27+
help="""Tell the CLI which account to run the command on by specifying a saved configuration - see
2828
`config` command.""")
2929
@click_log.simple_verbosity_option(logger)
30-
def cli(config, config_saved):
30+
@click.pass_context
31+
def cli(ctx, config, config_saved):
3132
if config:
3233
refresh_cloudinary_config(config)
3334
elif config_saved:
@@ -40,4 +41,9 @@ def cli(config, config_saved):
4041
if not is_valid_cloudinary_config():
4142
logger.warning("No Cloudinary configuration found.")
4243

44+
# If no subcommand was invoked, show help and exit with code 0
45+
if ctx.invoked_subcommand is None:
46+
click.echo(ctx.get_help())
47+
ctx.exit(0)
48+
4349
return True

cloudinary_cli/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from cloudinary_cli.core.utils import url, utils
99
from cloudinary_cli.core.overrides import resolve_command
1010

11-
setattr(click.MultiCommand, "resolve_command", resolve_command)
11+
setattr(click.Group, "resolve_command", resolve_command)
1212

1313
commands = [
1414
config,

cloudinary_cli/core/overrides.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
def resolve_command(self, ctx, args):
1010
# Patch the `resolve_command` function to enable simple commands (eg. cld resource)
1111
# Only core commands from API and modules are registered (eg. cld admin)
12+
13+
# Handle empty args (when CLI is invoked with no arguments)
14+
if not args:
15+
return None, None, []
16+
1217
cmd_name = make_str(args[0])
1318
original_cmd_name = cmd_name
1419

cloudinary_cli/modules/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def _normalize_remote_file_names(self, remote_files, local_files):
300300

301301
def _local_candidates(self, candidate_path):
302302
filename, extension = path.splitext(candidate_path)
303-
r = re.compile(f"({candidate_path}|{filename} \(\d+\){extension})")
303+
r = re.compile(f"({candidate_path}|{filename} \\(\\d+\\){extension})")
304304
# sort local files by base name (without ext) for accurate results.
305305
return dict(sorted({f: self.local_files[f]["etag"] for f in filter(r.match, self.local_files.keys())}.items(),
306306
key=lambda f: path.splitext(f[0])[0]))

0 commit comments

Comments
 (0)