[options] Fix `parse_known_args` for `--`

Closes #4167
This commit is contained in:
pukkandan 2022-06-25 08:38:52 +05:30
parent 14f25df2b6
commit c800598cd1
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39
1 changed files with 12 additions and 1 deletions

View File

@ -176,8 +176,19 @@ class _YoutubeDLOptionParser(optparse.OptionParser):
self.rargs, self.largs = self._get_args(args), []
self.values = values or self.get_default_values()
while self.rargs:
arg = self.rargs[0]
try:
self._process_args(self.largs, self.rargs, self.values)
if arg == '--':
del self.rargs[0]
break
elif arg.startswith('--'):
self._process_long_opt(self.rargs, self.values)
elif arg.startswith('-') and arg != '-':
self._process_short_opts(self.rargs, self.values)
elif self.allow_interspersed_args:
self.largs.append(self.rargs.pop(0))
else:
break
except optparse.OptParseError as err:
if isinstance(err, self._UNKNOWN_OPTION):
self.largs.append(err.opt_str)