Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --debug option #82

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions onetimepass/logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import logging

from onetimepass import settings
Expand All @@ -10,9 +11,10 @@
```
"""

logging.basicConfig(
logging_basic_config = functools.partial(
logging.basicConfig,
format="[%(asctime)s] %(levelname)s:%(module)s:%(lineno)d: %(message)s",
level=settings.LOG_LEVEL,
level=settings.DEFAULT_LOG_LEVEL,
)

logger = logging.getLogger(__name__)
17 changes: 16 additions & 1 deletion onetimepass/otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import functools
import json
import logging
import pathlib
import time
from typing import Dict
Expand Down Expand Up @@ -32,6 +33,7 @@
from onetimepass.exceptions import UnhandledFormatException
from onetimepass.exceptions import UnhandledOTPTypeException
from onetimepass.logging import logger
from onetimepass.logging import logging_basic_config
from onetimepass.otpauth import ParsingError
from onetimepass.otpauth import Uri

Expand Down Expand Up @@ -122,11 +124,24 @@ def validation_error_to_str(error: pydantic.ValidationError) -> str:
default=master_key.MasterKey.keyring_available(),
show_default="True if keyring installed, False otherwise",
)
@click.option(
"debug",
"-d/-D",
"--debug/--no-debug",
default=False,
show_default=True,
help="Enable/disable debug info.",
)
@click.pass_context
def otp(ctx: click.Context, color: bool, quiet: bool, keyring_: bool):
def otp(ctx: click.Context, color: bool, quiet: bool, keyring_: bool, debug: bool):
ctx.ensure_object(dict)
ctx.obj.update({"color": color, "quiet": quiet, "keyring_": keyring_})

if debug:
logging_basic_config(level=logging.DEBUG)
else:
logging_basic_config()


@otp.command(help="Print the one-time password for the specified ALIAS.")
@click.argument("alias")
Expand Down
4 changes: 1 addition & 3 deletions onetimepass/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@
KEYRING_SERVICE_NAME = APP_NAME
KEYRING_USERNAME = "master key"

LOG_LEVEL = (
logging.DEBUG
) # TODO change this for the production version OR implement CLI option for that
DEFAULT_LOG_LEVEL = logging.WARNING