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

View File

@ -14,7 +14,7 @@ from .limiter import Limiter
from .logging import ProgressBar, log
from .output_dir import FileSink, OnConflict, OutputDirectory, Redownload
from .transformer import Transformer
from .version import __version__
from .version import NAME, VERSION
class CrawlWarning(Exception):
@ -275,7 +275,7 @@ class HttpCrawler(Crawler):
pass
async with aiohttp.ClientSession(
headers={"User-Agent": f"pferd/{__version__}"},
headers={"User-Agent": f"{NAME}/{VERSION}"},
cookie_jar=cookie_jar,
) as 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]
name = PFERD
version = attr: PFERD.version.__version__
version = attr: PFERD.version.VERSION
[options]
packages = PFERD