Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add complete for shell by shtab #2976

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions contrib/completion/_you-get

This file was deleted.

31 changes: 0 additions & 31 deletions contrib/completion/you-get-completion.bash

This file was deleted.

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

entry_points = {'console_scripts': proj_info['console_scripts']},

install_requires=["shtab"],
extras_require={
'socks': ['PySocks'],
}
Expand Down
37 changes: 28 additions & 9 deletions src/you_get/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from importlib import import_module
from urllib import request, parse, error

import shtab
from .version import __version__
from .util import log, term
from .util.git import get_version
Expand Down Expand Up @@ -125,6 +126,23 @@
'zhibo' : 'zhibo',
'zhihu' : 'zhihu',
}
URL = {
"zsh": "_urls",
}
HOST = {
"zsh": "_hosts",
}
HOST_USER = {
"zsh": "_hosts_users",
}
# https://github.com/zsh-users/zsh/blob/master/Etc/completion-style-guide#L320-L323
PREAMBLE = {
"zsh": """\
_hosts_users() {
_alternative 'hosts: :_hosts' 'users: :_users'
}
""",
}

dry_run = False
json_output = False
Expand Down Expand Up @@ -1525,6 +1543,7 @@ def print_version():
description='A tiny downloader that scrapes the web',
add_help=False,
)
shtab.add_argument_to(parser, preamble=PREAMBLE)
parser.add_argument(
'-V', '--version', action='store_true',
help='Print version and exit'
Expand All @@ -1544,7 +1563,7 @@ def print_version():
dry_run_grp.add_argument(
'-u', '--url', action='store_true',
help='Print extracted information with URLs'
)
).complete = URL
dry_run_grp.add_argument(
'--json', action='store_true',
help='Print extracted URLs in JSON format'
Expand Down Expand Up @@ -1577,19 +1596,19 @@ def print_version():
)
download_grp.add_argument(
'-O', '--output-filename', metavar='FILE', help='Set output filename'
)
).complete = shtab.FILE
download_grp.add_argument(
'-o', '--output-dir', metavar='DIR', default='.',
help='Set output directory'
)
).complete = shtab.DIR
download_grp.add_argument(
'-p', '--player', metavar='PLAYER',
help='Stream extracted URL to a PLAYER'
)
download_grp.add_argument(
'-c', '--cookies', metavar='COOKIES_FILE',
help='Load cookies.txt or cookies.sqlite'
)
).complete = shtab.FILE
download_grp.add_argument(
'-t', '--timeout', metavar='SECONDS', type=int, default=600,
help='Set socket timeout'
Expand All @@ -1601,7 +1620,7 @@ def print_version():
download_grp.add_argument(
'-I', '--input-file', metavar='FILE', type=argparse.FileType('r'),
help='Read non-playlist URLs from FILE'
)
).complete = shtab.FILE
download_grp.add_argument(
'-P', '--password', help='Set video visit password to PASSWORD'
)
Expand Down Expand Up @@ -1639,18 +1658,18 @@ def print_version():
proxy_grp.add_argument(
'-x', '--http-proxy', metavar='HOST:PORT',
help='Use an HTTP proxy for downloading'
)
).complete = HOST
proxy_grp.add_argument(
'-y', '--extractor-proxy', metavar='HOST:PORT',
help='Use an HTTP proxy for extracting only'
)
).complete = HOST
proxy_grp.add_argument(
'--no-proxy', action='store_true', help='Never use a proxy'
)
proxy_grp.add_argument(
'-s', '--socks-proxy', metavar='HOST:PORT or USERNAME:PASSWORD@HOST:PORT',
help='Use an SOCKS5 proxy for downloading'
)
).complete = HOST_USER

download_grp.add_argument('--stream', help=argparse.SUPPRESS)
download_grp.add_argument('--itag', help=argparse.SUPPRESS)
Expand All @@ -1659,7 +1678,7 @@ def print_version():
help = 'download video using an m3u8 url')


parser.add_argument('URL', nargs='*', help=argparse.SUPPRESS)
parser.add_argument('URL', nargs='*').complete = URL

args = parser.parse_args()

Expand Down