Skip to content

Commit

Permalink
Add experimental flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Nov 17, 2023
1 parent ab56d7e commit b469fb2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
21 changes: 19 additions & 2 deletions pynitrokey/cli/nk3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pynitrokey.helpers import (
DownloadProgressBar,
Retries,
check_experimental_flag,
local_print,
require_windows_admin,
)
Expand Down Expand Up @@ -505,8 +506,16 @@ def version(ctx: Context) -> None:

@nk3.command()
@click.pass_obj
def factory_reset(ctx: Context) -> None:
@click.option(
"--experimental",
default=False,
is_flag=True,
help="Allow to execute experimental features",
hidden=True,
)
def factory_reset(ctx: Context, experimental: bool) -> None:
"""Factory reset all functionality of the device"""
check_experimental_flag(experimental)
with ctx.connect_device() as device:
device.factory_reset()

Expand All @@ -518,8 +527,16 @@ def factory_reset(ctx: Context) -> None:
@nk3.command()
@click.pass_obj
@click.argument("application", type=APPLICATIONS_CHOICE, required=True)
def factory_reset_app(ctx: Context, application: str) -> None:
@click.option(
"--experimental",
default=False,
is_flag=True,
help="Allow to execute experimental features",
hidden=True,
)
def factory_reset_app(ctx: Context, application: str, experimental: bool) -> None:
"""Factory reset all functionality of an application"""
check_experimental_flag(experimental)
with ctx.connect_device() as device:
device.factory_reset_app(application)

Expand Down
13 changes: 0 additions & 13 deletions pynitrokey/cli/nk3/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,6 @@ def abort_if_not_supported(cond: bool, name: str = "") -> None:
raise click.Abort()


def check_experimental_flag(experimental: bool) -> None:
"""Helper function to show common warning for the experimental features"""
if not experimental:
local_print(" ")
local_print(
"This feature is experimental, which means it was not tested thoroughly.\n"
"Note: data stored with it can be lost in the next firmware update.\n"
"Please pass --experimental switch to force running it anyway."
)
local_print(" ")
raise click.Abort()


def ask_to_touch_if_needed() -> None:
"""Helper function to show common request for the touch if device signalizes it"""
local_print("Please touch the device if it blinks", file=sys.stderr)
Expand Down
13 changes: 13 additions & 0 deletions pynitrokey/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,16 @@ def check_pynitrokey_version() -> None:

if not confirm("Do you still want to continue?", default=False):
raise click.Abort()


def check_experimental_flag(experimental: bool) -> None:
"""Helper function to show common warning for the experimental features"""
if not experimental:
local_print(" ")
local_print(
"This feature is experimental, which means it was not tested thoroughly.\n"
"Note: data stored with it can be lost in the next firmware update.\n"
"Please pass --experimental switch to force running it anyway."
)
local_print(" ")
raise click.Abort()

0 comments on commit b469fb2

Please sign in to comment.