Skip to content

Commit

Permalink
Allow manually coded error handling in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
credbbl committed Dec 19, 2023
1 parent 4f2d1e2 commit 5b9eb25
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/glvd/cli/client/cve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/glvd/cli/data/combine_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from __future__ import annotations

import asyncio
import logging

import asyncio
from sqlalchemy import (
select,
text,
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/glvd/cli/data/combine_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from __future__ import annotations

import asyncio
import logging
from typing import (
Any,
AsyncGenerator,
)

import asyncio
from sqlalchemy import (
bindparam,
select,
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/glvd/cli/data/ingest_debsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/glvd/cli/data/ingest_debsrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/glvd/cli/data/ingest_nvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/glvd/cli/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

0 comments on commit 5b9eb25

Please sign in to comment.