diff --git a/pynitrokey/cli/nk3/__init__.py b/pynitrokey/cli/nk3/__init__.py index 51580506..e92da37b 100644 --- a/pynitrokey/cli/nk3/__init__.py +++ b/pynitrokey/cli/nk3/__init__.py @@ -21,6 +21,7 @@ from pynitrokey.helpers import ( DownloadProgressBar, Retries, + check_experimental_flag, local_print, require_windows_admin, ) @@ -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() @@ -514,8 +523,16 @@ def factory_reset(ctx: Context) -> None: @nk3.command() @click.pass_obj @click.argument("application", type=click.STRING, 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) diff --git a/pynitrokey/cli/nk3/secrets.py b/pynitrokey/cli/nk3/secrets.py index 92ec0d22..f66d2fb7 100644 --- a/pynitrokey/cli/nk3/secrets.py +++ b/pynitrokey/cli/nk3/secrets.py @@ -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) diff --git a/pynitrokey/helpers.py b/pynitrokey/helpers.py index e8302289..622cf13d 100644 --- a/pynitrokey/helpers.py +++ b/pynitrokey/helpers.py @@ -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() diff --git a/pynitrokey/nk3/admin_app.py b/pynitrokey/nk3/admin_app.py index 5a824354..a6285e3f 100644 --- a/pynitrokey/nk3/admin_app.py +++ b/pynitrokey/nk3/admin_app.py @@ -186,7 +186,8 @@ def factory_reset(self) -> None: reply = self._call(AdminCommand.FACTORY_RESET, response_len=1) if reply is None: local_critical( - "Factory reset is not supported by the firmware version on the device", support_hint=False + "Factory reset is not supported by the firmware version on the device", + support_hint=False, ) return except OSError as e: