11import cloudinary
2- from click import command , option , echo
2+ from click import command , option , echo , BadParameter
33
44from cloudinary_cli .defaults import logger
5- from cloudinary_cli .utils .config_utils import load_config , verify_cloudinary_url , update_config , remove_config_keys
5+ from cloudinary_cli .utils .config_utils import load_config , verify_cloudinary_url , update_config , remove_config_keys , \
6+ show_cloudinary_config
67
78
89@command ("config" , help = "Display the current configuration, and manage additional configurations." )
910@option ("-n" , "--new" , help = """\b Create and name a configuration from a Cloudinary account environment variable.
1011e.g. cld config -n <NAME> <CLOUDINARY_URL>""" , nargs = 2 )
1112@option ("-ls" , "--ls" , help = "List all saved configurations." , is_flag = True )
13+ @option ("-s" , "--show" , help = "Show details of a specified configuration." , nargs = 1 )
1214@option ("-rm" , "--rm" , help = "Delete a specified configuration." , nargs = 1 )
1315@option ("-url" , "--from_url" ,
1416 help = "Create a configuration from a Cloudinary account environment variable. "
1517 "The configuration name is the cloud name." ,
1618 nargs = 1 )
17- def config (new , ls , rm , from_url ):
19+ def config (new , ls , show , rm , from_url ):
1820 if new or from_url :
1921 config_name , cloudinary_url = new or [None , from_url ]
2022
@@ -31,10 +33,17 @@ def config(new, ls, rm, from_url):
3133 if remove_config_keys (rm ):
3234 logger .warn (f"Configuration '{ rm } ' not found." )
3335 else :
34- logger .info (f"Configuration '{ rm } ' deleted" )
36+ logger .info (f"Configuration '{ rm } ' deleted. " )
3537 elif ls :
3638 echo ("\n " .join (load_config ().keys ()))
39+ elif show :
40+ curr_config = load_config ()
41+ if show not in curr_config :
42+ raise BadParameter (f"Configuration { show } does not exist, use -ls to list available configurations." )
43+
44+ config_obj = cloudinary .Config ()
45+ # noinspection PyProtectedMember
46+ config_obj ._setup_from_parsed_url (config_obj ._parse_cloudinary_url (load_config ()[show ]))
47+ show_cloudinary_config (config_obj )
3748 else :
38- obfuscated_config = {k : v if k != "api_secret" else "***************{}" .format (v [- 4 :])
39- for k , v in cloudinary .config ().__dict__ .items ()}
40- echo ('\n ' .join (["{}:\t {}" .format (k , v ) for k , v in obfuscated_config .items ()]))
49+ show_cloudinary_config (cloudinary .config ())
0 commit comments