@@ -270,12 +270,13 @@ def variadic_min_args(self) -> int:
270
270
args_count = len (self .type_args )
271
271
if args_count != 0 :
272
272
return args_count
273
- return self .extra_info .min_args
273
+ return self .extra_info .min_args if self . extra_info . min_args >= 1 else 1
274
274
else :
275
275
raise PydanticArgparserError ("variadic_min_args is only supported for variadic action" )
276
276
277
277
@property
278
278
def help_text (self ) -> list [str ]:
279
+ # Name
279
280
if isinstance (self , Argument ):
280
281
name = self .attribute_name
281
282
alias = "" if self .alias is None else f"({ self .alias } )"
@@ -288,6 +289,7 @@ def help_text(self) -> list[str]:
288
289
else :
289
290
raise IOError (f"Type { type (self )} not recognized" )
290
291
292
+ # Default
291
293
if self .action == "choice" and isinstance (self .default , Enum ):
292
294
default = "" if self .required else f"[Default: { str (self .default .name )} ]"
293
295
else :
@@ -296,20 +298,72 @@ def help_text(self) -> list[str]:
296
298
else :
297
299
default = "" if self .required else f"[Default: { str (self .default )} ]"
298
300
301
+ # Description
299
302
description = self .description
300
303
304
+ # Value
301
305
match self .action :
302
306
case "choice" :
303
307
input_ = "{" + f"{ '|' .join (self .choices )} " + "}"
304
308
case "store_false" | "store_true" :
305
309
input_ = "STORE"
310
+ case "variadic" :
311
+ if not self .type_args :
312
+ input_ = str (self .type .__name__ ).upper ()
313
+ input_ = f"{ input_ } [STR]"
314
+
315
+ i = 1
316
+ req_args = []
317
+ for _ in range (self .variadic_min_args ):
318
+ req_args .append (f"arg{ i } " )
319
+ i += 1
320
+ req_args = ", " .join (req_args )
321
+
322
+ if i < self .variadic_max_args :
323
+ req_args += ", {" f"arg{ i } , ..."
324
+
325
+ if self .variadic_max_args < float ("inf" ):
326
+ req_args += f", arg{ self .variadic_max_args } " + "}"
327
+ else :
328
+ req_args += "}"
329
+
330
+ input_ = f"{ input_ } ({ req_args } )"
331
+ elif self .type is tuple :
332
+ vals_help = [x .__name__ .upper () for x in self .type_args ]
333
+ vals_help = [f"arg{ x + 1 } { vals_help [x ]} " for x in range (len (vals_help ))]
334
+ vals_help = f"{ ', ' .join (vals_help )} "
335
+ input_ = str (self .type .__name__ ).upper ()
336
+ input_ = f"{ input_ } ({ vals_help } )"
337
+ else :
338
+ vals_help = self .type_args [0 ].__name__ .upper ()
339
+ input_ = str (self .type .__name__ ).upper ()
340
+ input_ = f"{ input_ } [{ vals_help } ]"
341
+
342
+ i = 1
343
+ req_args = []
344
+ for _ in range (self .variadic_min_args ):
345
+ req_args .append (f"arg{ i } " )
346
+ i += 1
347
+ req_args = ", " .join (req_args )
348
+
349
+ if i < self .variadic_max_args :
350
+ req_args += ", {" f"arg{ i } , ..."
351
+
352
+ if self .variadic_max_args < float ("inf" ):
353
+ req_args += f", arg{ self .variadic_max_args } " + "}"
354
+ else :
355
+ req_args += "}"
356
+
357
+ input_ = f"{ input_ } ({ req_args } )"
358
+
306
359
case _:
307
360
input_ = str (self .type .__name__ ).upper ()
308
361
309
362
if isinstance (self , Subcommand ):
310
363
input_ = ""
311
364
default = ""
312
365
366
+ # ###
313
367
result = [
314
368
name ,
315
369
alias ,
0 commit comments