Implement --version flag

This commit is contained in:
Joscha 2021-05-19 17:32:23 +02:00
parent 5916626399
commit 92886fb8d8
4 changed files with 15 additions and 4 deletions

View File

@ -6,8 +6,14 @@ from pathlib import Path
from .config import Config, ConfigDumpException, ConfigLoadException from .config import Config, ConfigDumpException, ConfigLoadException
from .output_dir import OnConflict, Redownload from .output_dir import OnConflict, Redownload
from .pferd import Pferd from .pferd import Pferd
from .version import NAME, VERSION
GENERAL_PARSER = argparse.ArgumentParser(add_help=False) GENERAL_PARSER = argparse.ArgumentParser(add_help=False)
GENERAL_PARSER.add_argument(
"--version",
action="store_true",
help="print version and exit"
)
GENERAL_PARSER.add_argument( GENERAL_PARSER.add_argument(
"--config", "-c", "--config", "-c",
type=Path, type=Path,
@ -211,6 +217,10 @@ def prune_crawlers(
def main() -> None: def main() -> None:
args = PARSER.parse_args() args = PARSER.parse_args()
if args.version:
print(f"{NAME} {VERSION}")
exit()
try: try:
config = Config(load_parser(args)) config = Config(load_parser(args))
except ConfigLoadException: except ConfigLoadException:

View File

@ -14,7 +14,7 @@ from .limiter import Limiter
from .logging import ProgressBar, log from .logging import ProgressBar, log
from .output_dir import FileSink, OnConflict, OutputDirectory, Redownload from .output_dir import FileSink, OnConflict, OutputDirectory, Redownload
from .transformer import Transformer from .transformer import Transformer
from .version import __version__ from .version import NAME, VERSION
class CrawlWarning(Exception): class CrawlWarning(Exception):
@ -275,7 +275,7 @@ class HttpCrawler(Crawler):
pass pass
async with aiohttp.ClientSession( async with aiohttp.ClientSession(
headers={"User-Agent": f"pferd/{__version__}"}, headers={"User-Agent": f"{NAME}/{VERSION}"},
cookie_jar=cookie_jar, cookie_jar=cookie_jar,
) as session: ) as session:
self.session = session self.session = session

View File

@ -1 +1,2 @@
__version__ = "3.0.0" NAME = "PFERD"
VERSION = "3.0.0"

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = PFERD name = PFERD
version = attr: PFERD.version.__version__ version = attr: PFERD.version.VERSION
[options] [options]
packages = PFERD packages = PFERD