diff options
author | Simon Sawicki <contact@grub4k.xyz> | 2023-05-24 20:35:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-24 20:35:07 +0200 |
commit | 8417f26b8a819cd7ffcd4e000ca3e45033e670fb (patch) | |
tree | e0227cf0f6b96fc89235d259effad6bd5ec8891c /yt_dlp/options.py | |
parent | 7aeda6cc9e73ada0b0a0b6a6748c66bef63a20a8 (diff) | |
download | hypervideo-pre-8417f26b8a819cd7ffcd4e000ca3e45033e670fb.tar.lz hypervideo-pre-8417f26b8a819cd7ffcd4e000ca3e45033e670fb.tar.xz hypervideo-pre-8417f26b8a819cd7ffcd4e000ca3e45033e670fb.zip |
[core] Implement `--color` flag (#6904)
Authored by: Grub4K
Diffstat (limited to 'yt_dlp/options.py')
-rw-r--r-- | yt_dlp/options.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/yt_dlp/options.py b/yt_dlp/options.py index 838d79fcb..fecc27403 100644 --- a/yt_dlp/options.py +++ b/yt_dlp/options.py @@ -34,6 +34,7 @@ from .utils import ( join_nonempty, orderedSet_from_options, remove_end, + variadic, write_string, ) from .version import CHANNEL, __version__ @@ -250,7 +251,7 @@ def create_parser(): if multiple_args: val = [val, *value[1:]] elif default_key is not None: - keys, val = [default_key], value + keys, val = variadic(default_key), value else: raise optparse.OptionValueError( f'wrong {opt_str} formatting; it should be {option.metavar}, not "{value}"') @@ -440,8 +441,25 @@ def create_parser(): help='Do not mark videos watched (default)') general.add_option( '--no-colors', '--no-colours', - action='store_true', dest='no_color', default=False, - help='Do not emit color codes in output (Alias: --no-colours)') + action='store_const', dest='color', const={ + 'stdout': 'no_color', + 'stderr': 'no_color', + }, + help=optparse.SUPPRESS_HELP) + general.add_option( + '--color', + dest='color', metavar='[STREAM:]POLICY', default={}, type='str', + action='callback', callback=_dict_from_options_callback, + callback_kwargs={ + 'allowed_keys': 'stdout|stderr', + 'default_key': ['stdout', 'stderr'], + 'process': str.strip, + }, help=( + 'Whether to emit color codes in output, optionally prefixed by ' + 'the STREAM (stdout or stderr) to apply the setting to. ' + 'Can be one of "always", "auto" (default), "never", or ' + '"no_color" (use non color terminal sequences). ' + 'Can be used multiple times')) general.add_option( '--compat-options', metavar='OPTS', dest='compat_opts', default=set(), type='str', |