diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-02-10 21:07:08 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-02-11 12:07:03 +0530 |
commit | db2e129ca0c11de84d57b2298dffd5d87e852518 (patch) | |
tree | beab776884a7c0249da540ffc6ed6501e16f9462 | |
parent | 1209b6ca5b720a2cd035ff86040bfb1fea7ac6c9 (diff) | |
download | hypervideo-pre-db2e129ca0c11de84d57b2298dffd5d87e852518.tar.lz hypervideo-pre-db2e129ca0c11de84d57b2298dffd5d87e852518.tar.xz hypervideo-pre-db2e129ca0c11de84d57b2298dffd5d87e852518.zip |
[options] Better ambiguous option resolution
Eg: `--write-auto` no longer results in
> ambiguous option: --write-auto (--write-auto-subs, --write-automatic-subs?)
-rw-r--r-- | yt_dlp/options.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/yt_dlp/options.py b/yt_dlp/options.py index a6d7c17eb..d89f74ac5 100644 --- a/yt_dlp/options.py +++ b/yt_dlp/options.py @@ -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( |