From 5b9eb2553fcd39995c8c39ca1b6e78fdfa2d7e55 Mon Sep 17 00:00:00 2001 From: Bastian Blank Date: Tue, 19 Dec 2023 11:50:24 +0100 Subject: [PATCH] Allow manually coded error handling in CLI --- src/glvd/cli/client/cve.py | 2 +- src/glvd/cli/data/combine_all.py | 4 ++-- src/glvd/cli/data/combine_deb.py | 4 ++-- src/glvd/cli/data/ingest_debsec.py | 4 ++-- src/glvd/cli/data/ingest_debsrc.py | 4 ++-- src/glvd/cli/data/ingest_nvd.py | 4 ++-- src/glvd/cli/registry.py | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/glvd/cli/client/cve.py b/src/glvd/cli/client/cve.py index d8fc4ad..62367bb 100644 --- a/src/glvd/cli/client/cve.py +++ b/src/glvd/cli/client/cve.py @@ -28,7 +28,7 @@ class ClientCve: ), ] ) - def run(cve: str, server: str, debug: bool) -> None: + def run(*, argparser: None, cve: str, server: str, debug: bool) -> None: logging.basicConfig(level=debug and logging.DEBUG or logging.INFO) ClientCve(server)(cve) diff --git a/src/glvd/cli/data/combine_all.py b/src/glvd/cli/data/combine_all.py index 4497c1b..ffff95e 100644 --- a/src/glvd/cli/data/combine_all.py +++ b/src/glvd/cli/data/combine_all.py @@ -2,9 +2,9 @@ from __future__ import annotations +import asyncio import logging -import asyncio from sqlalchemy import ( select, text, @@ -26,7 +26,7 @@ class CombineAll: @staticmethod @cli.register('combine-all') - def run(database: str, debug: bool) -> None: + def run(*, argparser: None, database: str, debug: bool) -> None: logging.basicConfig(level=debug and logging.DEBUG or logging.INFO) engine = create_async_engine(database, echo=debug) asyncio.run(CombineAll()(engine)) diff --git a/src/glvd/cli/data/combine_deb.py b/src/glvd/cli/data/combine_deb.py index 5cec3a1..b2ec5e5 100644 --- a/src/glvd/cli/data/combine_deb.py +++ b/src/glvd/cli/data/combine_deb.py @@ -2,13 +2,13 @@ from __future__ import annotations +import asyncio import logging from typing import ( Any, AsyncGenerator, ) -import asyncio from sqlalchemy import ( bindparam, select, @@ -33,7 +33,7 @@ class CombineDeb: @staticmethod @cli.register('combine-deb') - def run(database: str, debug: bool) -> None: + def run(*, argparser: None, database: str, debug: bool) -> None: logging.basicConfig(level=debug and logging.DEBUG or logging.INFO) engine = create_async_engine(database, echo=debug) asyncio.run(CombineDeb()(engine)) diff --git a/src/glvd/cli/data/ingest_debsec.py b/src/glvd/cli/data/ingest_debsec.py index a68128f..6620d51 100644 --- a/src/glvd/cli/data/ingest_debsec.py +++ b/src/glvd/cli/data/ingest_debsec.py @@ -2,10 +2,10 @@ from __future__ import annotations +import asyncio import logging from pathlib import Path -import asyncio from sqlalchemy import select from sqlalchemy.ext.asyncio import ( AsyncEngine, @@ -42,7 +42,7 @@ class IngestDebsec: ), ] ) - def run(cpe_product: str, dir: Path, database: str, debug: bool) -> None: + def run(*, argparser: None, cpe_product: str, dir: Path, database: str, debug: bool) -> None: logging.basicConfig(level=debug and logging.DEBUG or logging.INFO) engine = create_async_engine(database, echo=debug) asyncio.run(IngestDebsec(cpe_product, dir)(engine)) diff --git a/src/glvd/cli/data/ingest_debsrc.py b/src/glvd/cli/data/ingest_debsrc.py index 6f43198..ba3d8c6 100644 --- a/src/glvd/cli/data/ingest_debsrc.py +++ b/src/glvd/cli/data/ingest_debsrc.py @@ -2,10 +2,10 @@ from __future__ import annotations +import asyncio import logging from pathlib import Path -import asyncio from sqlalchemy import select from sqlalchemy.ext.asyncio import ( AsyncEngine, @@ -47,7 +47,7 @@ class IngestDebsrc: ), ] ) - def run(cpe_product: str, deb_codename: str, file: Path, database: str, debug: bool) -> None: + def run(*, argparser: None, cpe_product: str, deb_codename: str, file: Path, database: str, debug: bool) -> None: logging.basicConfig(level=debug and logging.DEBUG or logging.INFO) engine = create_async_engine(database, echo=debug) asyncio.run(IngestDebsrc(cpe_product, deb_codename, file)(engine)) diff --git a/src/glvd/cli/data/ingest_nvd.py b/src/glvd/cli/data/ingest_nvd.py index 60982ac..c3c0343 100644 --- a/src/glvd/cli/data/ingest_nvd.py +++ b/src/glvd/cli/data/ingest_nvd.py @@ -2,11 +2,11 @@ from __future__ import annotations +import asyncio import logging from datetime import datetime, timedelta, timezone from typing import Any -import asyncio from sqlalchemy import func, select from sqlalchemy.dialects.postgresql import insert from sqlalchemy.ext.asyncio import ( @@ -28,7 +28,7 @@ class IngestNvd: @staticmethod @cli.register('ingest-nvd') - def run(database: str, debug: bool) -> None: + def run(*, argparser: None, database: str, debug: bool) -> None: logging.basicConfig(level=debug and logging.DEBUG or logging.INFO) engine = create_async_engine(database, echo=debug) asyncio.run(IngestNvd()(engine)) diff --git a/src/glvd/cli/registry.py b/src/glvd/cli/registry.py index 942210c..a6e3bcd 100644 --- a/src/glvd/cli/registry.py +++ b/src/glvd/cli/registry.py @@ -69,7 +69,7 @@ def wrap(func: Callable) -> Callable: def run() -> None: args = parser_main.parse_args() - func(**vars(args)) + func(argparser=self.parser, **vars(args)) return run @@ -80,6 +80,6 @@ def main(self) -> None: v = vars(args) func = v.pop('func', None) if func: - func(**v) + func(argparser=self.parser, **v) else: self.parser.print_help()