@@ -10,8 +10,14 @@ class CliWarning(ABC):
10
10
def __repr__ (self ):
11
11
return self .__str__ ()
12
12
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__
15
21
16
22
17
23
class ConfigLoadWarning (CliWarning ):
@@ -23,22 +29,24 @@ def __init__(self, paths: Dict[str, bool]):
23
29
self .paths = paths
24
30
self .message = "Failed to load config files. Tried the following paths: \n "
25
31
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 "
28
34
29
35
def __str__ (self ):
30
36
return f"{ self .__class__ .__name__ } - { self .paths } "
31
37
32
38
33
39
class ProfileNotFoundWarning (CliWarning ):
34
40
"""
35
- Warning for issues loading the configuration file .
41
+ Warning for issues finding the requested profile .
36
42
"""
37
43
38
- def __init__ (self , path , profile ):
39
- self .path = path
44
+ def __init__ (self , paths , profile ):
45
+ self .path = paths
40
46
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 "
42
50
43
51
def __str__ (self ):
44
52
return f"{ self .__class__ .__name__ } - { self .path } - { self .profile } "
@@ -51,11 +59,11 @@ class ApiAuthenticationWarning(CliWarning):
51
59
52
60
def __init__ (self , cloudsmith_host ):
53
61
self .cloudsmith_host = cloudsmith_host
54
- self .message = "\n " .join (
62
+ self .message = "" .join (
55
63
[
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 " ,
59
67
]
60
68
)
61
69
@@ -78,20 +86,21 @@ def append(self, warning: CliWarning):
78
86
def __dedupe__ (self ) -> List [CliWarning ]:
79
87
return list (set (self .warnings ))
80
88
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 )
86
92
87
93
def __repr__ (self ) -> str :
94
+ return self .__str__ ()
95
+
96
+ def __str__ (self ) -> str :
88
97
return "," .join ([str (x ) for x in self .warnings ])
89
98
90
99
def __len__ (self ) -> int :
91
100
return len (self .warnings )
92
101
93
102
94
103
def get_or_create_warnings (ctx ):
95
- """Get or create the options object."""
104
+ """Get or create the warnings object."""
96
105
97
106
return ctx .ensure_object (CliWarnings )
0 commit comments