Add --version option to print program version

This commit is contained in:
Ivan Habunek 2019-07-05 13:14:22 +02:00
parent cbb0d6cfbd
commit 3e7f310e36
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95

View File

@ -5,7 +5,7 @@ from collections import namedtuple
from twitchdl.exceptions import ConsoleError
from twitchdl.output import print_err
from . import commands
from . import commands, __version__
Command = namedtuple("Command", ["name", "description", "arguments"])
@ -93,6 +93,8 @@ def get_parser():
description = "A script for downloading videos from Twitch"
parser = ArgumentParser(prog='twitch-dl', description=description, epilog=CLIENT_WEBSITE)
parser.add_argument("--version", help="show version number", action='store_true')
subparsers = parser.add_subparsers(title="commands")
for command in COMMANDS:
@ -111,6 +113,10 @@ def main():
parser = get_parser()
args = parser.parse_args()
if args.version:
print("twitch-dl v{}".format(__version__))
return
if "func" not in args:
parser.print_help()
return