@@ -42,11 +42,16 @@ def __init__(self, *args, delimiter=',', resolve_full: bool = True, **kwargs):
42
42
self .resolve_full = resolve_full
43
43
44
44
def convert (self , value , param , ctx ):
45
- if not isinstance (value , str ):
45
+ # logging.warning(f"{param=} convert called with `{value=}`, `{type(value)=}`")
46
+ if isinstance (value , str ):
47
+ res = value .split (self .delimiter )
48
+ elif isinstance (value , (list , tuple )):
49
+ res = value
50
+ else :
46
51
raise click .BadParameter (f"Expected a comma-separated string, got { value } " )
47
- res = value .split (self .delimiter )
48
52
if self .resolve_full :
49
53
res = [os .path .abspath (v ) for v in res ]
54
+ # logging.warning(f"{param=} convert returning `{res=}`")
50
55
return res
51
56
52
57
def shell_complete (self , ctx , param , incomplete ):
@@ -83,8 +88,12 @@ def __init__(self, *args, delimiter=',', **kwargs):
83
88
84
89
def convert (self , value , param , ctx ):
85
90
if isinstance (value , str ):
86
- return value .split (self .delimiter )
87
- raise click .BadParameter (f"Expected a string or a comma-separated string, got { value } " )
91
+ res = value .split (self .delimiter )
92
+ elif isinstance (value , (list , tuple )):
93
+ res = value
94
+ else :
95
+ raise click .BadParameter (f"Expected a string or a comma-separated string, got { value } " )
96
+ return res
88
97
89
98
def shell_complete (self , ctx , param , incomplete ):
90
99
last = incomplete .rsplit (self .delimiter , 1 )[- 1 ]
@@ -124,13 +133,15 @@ def __post_init__(self):
124
133
125
134
def to_click_option_dec (self ):
126
135
"""Convert OptionData to a click.Option."""
127
- decls = [f"--{ self .name } " ]
136
+ decl = f"--{ self .name } "
137
+ other_decls = []
128
138
if self .short :
129
- decls .insert (0 , f"-{ self .short } " )
139
+ other_decls .insert (0 , f"-{ self .short } " )
130
140
131
141
kwargs = {
132
142
'help' : self .description ,
133
143
'default' : self .default ,
144
+ 'is_flag' : False ,
134
145
'show_default' : True ,
135
146
'type' : None
136
147
}
@@ -139,7 +150,6 @@ def to_click_option_dec(self):
139
150
kwargs ['type' ] = DelimitedString (delimiter = ',' )
140
151
kwargs ['multiple' ] = True
141
152
elif self .type in ['pathlist' , 'pathtuple' ]:
142
- # kwargs['type'] = DelimitedPathList(delimiter=os.pathsep)
143
153
kwargs ['type' ] = DelimitedPathList (delimiter = ',' )
144
154
kwargs ['multiple' ] = True
145
155
elif self .type in ['urllist' , 'urltuple' ]:
@@ -148,7 +158,7 @@ def to_click_option_dec(self):
148
158
elif self .type == 'choice' :
149
159
if self .lst is None :
150
160
raise ValueError (f"Choice type requires a list of choices for option { self .name } " )
151
- kwargs ['type' ] = click .Choice (self .lst , case_sensitive = False )
161
+ kwargs ['type' ] = click .Choice (self .lst , case_sensitive = True )
152
162
elif self .type in ['int' , int ]:
153
163
kwargs ['type' ] = click .INT
154
164
elif self .type in ['float' , float ]:
@@ -159,10 +169,18 @@ def to_click_option_dec(self):
159
169
if self .default is False or self .default is True :
160
170
kwargs ['is_flag' ] = True
161
171
kwargs ['type' ] = click .BOOL
172
+ if self .action in ['store_true' , 'store_false' ]:
173
+ decl = f"--{ self .name } /--disable-{ self .name } "
162
174
elif isinstance (self .default , (list , tuple )):
163
175
kwargs ['multiple' ] = True
164
176
kwargs ['type' ] = click .STRING
165
177
178
+ if self .action == 'store_or_None' :
179
+ kwargs ['default' ] = None
180
+ kwargs ['flag_value' ] = self .default
181
+
182
+ decls = other_decls + [decl ]
183
+
166
184
return click .option (
167
185
* decls ,
168
186
expose_value = False ,
0 commit comments