-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcli_group.py
More file actions
54 lines (44 loc) · 1.9 KB
/
cli_group.py
File metadata and controls
54 lines (44 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
import platform
import shutil
import os
import click
import click_log
import cloudinary
from dotenv import load_dotenv
from cloudinary_cli.defaults import logger
from cloudinary_cli.utils.config_utils import load_config, refresh_cloudinary_config, \
is_valid_cloudinary_config
from cloudinary_cli.version import __version__ as cli_version
# Load environment variables from .env file
load_dotenv()
CONTEXT_SETTINGS = dict(max_content_width=shutil.get_terminal_size()[0], terminal_width=shutil.get_terminal_size()[0])
@click.group(context_settings=CONTEXT_SETTINGS, invoke_without_command=True)
@click.help_option()
@click.version_option(cli_version, prog_name="Cloudinary CLI",
message=f"%(prog)s, version %(version)s\n"
f"Cloudinary SDK, version {cloudinary.VERSION}\n"
f"Python, version {platform.python_version()}")
@click.option("-c", "--config",
help="""Tell the CLI which account to run the command on by specifying an account environment variable."""
)
@click.option("-C", "--config_saved",
help="""Tell the CLI which account to run the command on by specifying a saved configuration - see
`config` command.""")
@click_log.simple_verbosity_option(logger)
@click.pass_context
def cli(ctx, config, config_saved):
if config:
refresh_cloudinary_config(config)
elif config_saved:
config = load_config()
if config_saved not in config:
raise Exception(f"Config {config_saved} does not exist")
refresh_cloudinary_config(config[config_saved])
if not is_valid_cloudinary_config():
logger.warning("No Cloudinary configuration found.")
# If no subcommand was invoked, show help and exit with code 0
if ctx.invoked_subcommand is None:
click.echo(ctx.get_help())
ctx.exit(0)
return True