mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-11-16 07:48:01 +01:00
[options] Better ambiguous option resolution
Eg: `--write-auto` no longer results in > ambiguous option: --write-auto (--write-auto-subs, --write-automatic-subs?)
This commit is contained in:
parent
1209b6ca5b
commit
db2e129ca0
1 changed files with 14 additions and 1 deletions
|
@ -117,6 +117,19 @@ def parseOpts(overrideArguments=None, ignore_config_files='if_override'):
|
|||
return parser, opts, args
|
||||
|
||||
|
||||
class _YoutubeDLOptionParser(optparse.OptionParser):
|
||||
# optparse is deprecated since python 3.2. So assume a stable interface even for private methods
|
||||
|
||||
def _match_long_opt(self, opt):
|
||||
"""Improve ambigious argument resolution by comparing option objects instead of argument strings"""
|
||||
try:
|
||||
return super()._match_long_opt(opt)
|
||||
except optparse.AmbiguousOptionError as e:
|
||||
if len(set(self._long_opt[p] for p in e.possibilities)) == 1:
|
||||
return e.possibilities[0]
|
||||
raise
|
||||
|
||||
|
||||
def create_parser():
|
||||
def _format_option_string(option):
|
||||
''' ('-o', '--option') -> -o, --format METAVAR'''
|
||||
|
@ -215,7 +228,7 @@ def create_parser():
|
|||
'conflict_handler': 'resolve',
|
||||
}
|
||||
|
||||
parser = optparse.OptionParser(**compat_kwargs(kw))
|
||||
parser = _YoutubeDLOptionParser(**compat_kwargs(kw))
|
||||
|
||||
general = optparse.OptionGroup(parser, 'General Options')
|
||||
general.add_option(
|
||||
|
|
Loading…
Reference in a new issue