@@ -39,6 +39,7 @@ def smart_split(ipt: str, args_data: dict, subcommand: bool = False) -> typing.T
3939 last_arg = args_data [args_name [- 1 ]]
4040 var_positional_in = True in [* map (lambda n : n ["kind" ] == n ["kind" ].VAR_POSITIONAL , args_data .values ())]
4141 keyword_only_count = len ([x for x in args_data .values () if x ["kind" ] == x ["kind" ].KEYWORD_ONLY ])
42+ all_optional = bool ([x for x in args_data .values () if x ["required" ] is False ])
4243 if len (args_data ) == 1 :
4344 if last_arg ["kind" ] == last_arg ["kind" ].VAR_POSITIONAL :
4445 if ipt :
@@ -54,14 +55,17 @@ def smart_split(ipt: str, args_data: dict, subcommand: bool = False) -> typing.T
5455 return [initial_split [0 ]] if initial_split else [], {}
5556 if (len (initial_split ) == len (args_data ) and not keyword_only_count ) or last_arg ["kind" ] == last_arg ["kind" ].VAR_POSITIONAL : # assuming this matches
5657 return initial_split , {}
57- if len (initial_split ) != len (args_data ) and not var_positional_in and not keyword_only_count :
58+ if len (initial_split ) != len (args_data ) and not var_positional_in and not keyword_only_count and not all_optional :
5859 raise ValueError ("argument count does not match." )
5960 if keyword_only_count > 1 :
6061 raise AttributeError ("maximum keyword-only param number is 1." )
6162 args = []
6263 kwargs = {}
6364 if not ipt .replace (" " , "" ):
64- raise ValueError ("empty input." )
65+ for v in args_data .values ():
66+ if v ["required" ]:
67+ raise ValueError ("empty input." )
68+ return [], {}
6569 for i , x in enumerate (args_data .items ()):
6670 k , v = x
6771 if v ["kind" ] == v ["kind" ].KEYWORD_ONLY :
@@ -70,7 +74,10 @@ def smart_split(ipt: str, args_data: dict, subcommand: bool = False) -> typing.T
7074 kwargs [k ] = ipt or None
7175 # TODO: fix kwargs is added even if it is not present
7276 break
73- args .append (initial_split [i ])
77+ if i < len (initial_split ):
78+ args .append (initial_split [i ])
79+ else :
80+ break
7481 ipt = ipt .split (initial_split [i ], 1 )[- 1 ].lstrip ()
7582 return args , kwargs
7683
0 commit comments