@@ -10,8 +10,14 @@ class CliWarning(ABC):
1010 def __repr__ (self ):
1111 return self .__str__ ()
1212
13- def __str__ (self ):
14- return f"{ self .__class__ .__name__ } "
13+ def __hash__ (self ):
14+ return hash (self .__str__ ())
15+
16+ def __eq__ (self , other ):
17+ if not isinstance (other , self .__class__ ):
18+ return False
19+
20+ return self .__dict__ == other .__dict__
1521
1622
1723class ConfigLoadWarning (CliWarning ):
@@ -23,22 +29,24 @@ def __init__(self, paths: Dict[str, bool]):
2329 self .paths = paths
2430 self .message = "Failed to load config files. Tried the following paths: \n "
2531 for path , exists in paths .items ():
26- self .message += f" - { path } - exists: { exists } ) \n "
27- self .message += "You may need to run `cloudsmith login` to authenticate and create a config file."
32+ self .message += f" - { path } - exists: { exists } \n "
33+ self .message += "You may need to run `cloudsmith login` to authenticate and create a config file. \n "
2834
2935 def __str__ (self ):
3036 return f"{ self .__class__ .__name__ } - { self .paths } "
3137
3238
3339class ProfileNotFoundWarning (CliWarning ):
3440 """
35- Warning for issues loading the configuration file .
41+ Warning for issues finding the requested profile .
3642 """
3743
38- def __init__ (self , path , profile ):
39- self .path = path
44+ def __init__ (self , paths , profile ):
45+ self .path = paths
4046 self .profile = profile
41- self .message = f"Failed to load config file: { path } for profile: { profile } "
47+ self .message = f"Failed to load profile { profile } from config. Tried the following paths: \n "
48+ for path , exists in paths .items ():
49+ self .message += f" - { path } - exists: { exists } \n "
4250
4351 def __str__ (self ):
4452 return f"{ self .__class__ .__name__ } - { self .path } - { self .profile } "
@@ -51,11 +59,11 @@ class ApiAuthenticationWarning(CliWarning):
5159
5260 def __init__ (self , cloudsmith_host ):
5361 self .cloudsmith_host = cloudsmith_host
54- self .message = "\n " .join (
62+ self .message = "" .join (
5563 [
56- "Failed to authenticate with Cloudsmith API" ,
57- "Please check your credentials and try again" ,
58- f"Host: { cloudsmith_host } " ,
64+ "Failed to authenticate with Cloudsmith API " ,
65+ "Please check your credentials and try again. \n " ,
66+ f"Host: { cloudsmith_host } \n " ,
5967 ]
6068 )
6169
@@ -78,20 +86,21 @@ def append(self, warning: CliWarning):
7886 def __dedupe__ (self ) -> List [CliWarning ]:
7987 return list (set (self .warnings ))
8088
81- def report (self ) -> List [CliWarning ]:
82- return self .__dedupe__ ()
83-
84- def __str__ (self ) -> str :
85- return "," .join ([str (x ) for x in self .warnings ])
89+ def display (self , display_fn ):
90+ for warning in self .__dedupe__ ():
91+ display_fn (warning .message )
8692
8793 def __repr__ (self ) -> str :
94+ return self .__str__ ()
95+
96+ def __str__ (self ) -> str :
8897 return "," .join ([str (x ) for x in self .warnings ])
8998
9099 def __len__ (self ) -> int :
91100 return len (self .warnings )
92101
93102
94103def get_or_create_warnings (ctx ):
95- """Get or create the options object."""
104+ """Get or create the warnings object."""
96105
97106 return ctx .ensure_object (CliWarnings )
0 commit comments