Skip to content

Commit

Permalink
Set up logging CLI arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
multimeric committed Aug 20, 2024
1 parent 36bc6d5 commit 8e1ccdc
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions filesender/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
import logging
from typing import Any, List, Optional, Callable, Coroutine, Dict
from typing_extensions import Annotated, ParamSpec, TypeVar
from filesender.api import FileSenderClient
Expand All @@ -10,6 +11,10 @@
from functools import wraps
from asyncio import run
from importlib.metadata import version
from rich.logging import RichHandler
from filesender.log import LogParam, LogLevel

Check failure on line 15 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Import "filesender.log" could not be resolved (reportMissingImports)

Check failure on line 15 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Import "filesender.log" could not be resolved (reportMissingImports)

Check failure on line 15 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Import "filesender.log" could not be resolved (reportMissingImports)

Check failure on line 15 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Import "filesender.log" could not be resolved (reportMissingImports)

logger = logging.getLogger(__name__)

from filesender.response_types import Guest, Transfer

Expand Down Expand Up @@ -46,19 +51,25 @@ def common_args(
context: Context,
version: Annotated[
Optional[bool], Option("--version", callback=version_callback)
] = None
] = None,
log_level: Annotated[

Check failure on line 55 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Type of parameter "log_level" is unknown (reportUnknownParameterType)

Check failure on line 55 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Type of parameter "log_level" is unknown (reportUnknownParameterType)

Check failure on line 55 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Type of parameter "log_level" is unknown (reportUnknownParameterType)

Check failure on line 55 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Type of parameter "log_level" is unknown (reportUnknownParameterType)
LogLevel, Option("--log-level", click_type=LogParam(), help="Logging verbosity")

Check failure on line 56 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Argument type is unknown   Argument corresponds to parameter "click_type" in function "Option" (reportUnknownArgumentType)

Check failure on line 56 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Argument type is unknown   Argument corresponds to parameter "click_type" in function "Option" (reportUnknownArgumentType)

Check failure on line 56 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Argument type is unknown   Argument corresponds to parameter "click_type" in function "Option" (reportUnknownArgumentType)

Check failure on line 56 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Argument type is unknown   Argument corresponds to parameter "click_type" in function "Option" (reportUnknownArgumentType)
] = LogLevel.WARNING
):
context.obj = {
"base_url": base_url
}
logging.basicConfig(
level=log_level.value, format= "%(message)s", datefmt="[%X]", handlers=[RichHandler()]

Check failure on line 63 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Argument type is unknown   Argument corresponds to parameter "level" in function "basicConfig" (reportUnknownArgumentType)

Check failure on line 63 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Argument type is unknown   Argument corresponds to parameter "level" in function "basicConfig" (reportUnknownArgumentType)

Check failure on line 63 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Argument type is unknown   Argument corresponds to parameter "level" in function "basicConfig" (reportUnknownArgumentType)

Check failure on line 63 in filesender/main.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Argument type is unknown   Argument corresponds to parameter "level" in function "basicConfig" (reportUnknownArgumentType)
)


@app.command(context_settings=context)
def invite(
username: Annotated[str, Option(help="Your username. This is the username of the person doing the inviting, not the person being invited.")],
apikey: Annotated[str, Option(help="Your API token. This is the token of the person doing the inviting, not the person being invited.")],
recipient: Annotated[str, Argument(help="The email address of the person to invite")],
context: Context,
verbose: Verbose = False,
# Although these parameters are exact duplicates of those in GuestOptions,
# typer doesn't support re-using argument lists: https://github.com/tiangolo/typer/discussions/665
one_time: Annotated[bool, Option(help="If true, this voucher is only valid for one use, otherwise it can be re-used.")] = True,
Expand Down Expand Up @@ -99,9 +110,8 @@ def invite(
}
}
}))
if verbose:
print(result)
print("Invitation successfully sent")
logger.info(result)
logger.info("Invitation successfully sent")

@app.command(context_settings=context)
@typer_async
Expand All @@ -113,7 +123,6 @@ async def upload_voucher(
concurrent_files: ConcurrentFiles = None,
concurrent_chunks: ConcurrentChunks = None,
chunk_size: ChunkSize = None,
verbose: Verbose = False
):
"""
Uploads files to a voucher that you have been invited to
Expand All @@ -129,9 +138,8 @@ async def upload_voucher(
await auth.prepare(client.http_client)
await client.prepare()
result: Transfer = await client.upload_workflow(files, {"from": email, "recipients": []})
if verbose:
print(result)
print("Upload completed successfully")
logger.info(result)
logger.info("Upload completed successfully")

@app.command(context_settings=context)
@typer_async
Expand All @@ -141,7 +149,6 @@ async def upload(
files: UploadFiles,
recipients: Annotated[List[str], Option(show_default=False, help="One or more email addresses to send the files")],
context: Context,
verbose: Verbose = False,
concurrent_files: ConcurrentFiles = None,
concurrent_chunks: ConcurrentChunks = None,
chunk_size: ChunkSize = None,
Expand All @@ -163,9 +170,8 @@ async def upload(
)
await client.prepare()
result: Transfer = await client.upload_workflow(files, {"recipients": recipients, "from": username})
if verbose:
print(result)
print("Upload completed successfully")
logger.info(result)
logger.info("Upload completed successfully")

@app.command(context_settings=context)
def download(
Expand Down

0 comments on commit 8e1ccdc

Please sign in to comment.