forked from Nitrokey/libnitrokey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Nitrokey#152 from robin-nitrokey/cli-exception
cli: Add CliException for easier error handling
- Loading branch information
Showing
2 changed files
with
61 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2022 Nitrokey Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or | ||
# http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or | ||
# http://opensource.org/licenses/MIT>, at your option. This file may not be | ||
# copied, modified, or distributed except according to those terms. | ||
|
||
import click | ||
|
||
from pynitrokey.helpers import local_critical | ||
|
||
|
||
class CliException(click.ClickException): | ||
def __init__( | ||
self, *messages, support_hint: bool = True, ret_code: int = 1, **kwargs | ||
): | ||
super().__init__("\n".join(messages)) | ||
|
||
self.messages = messages | ||
self.support_hint = support_hint | ||
self.ret_code = ret_code | ||
self.kwargs = kwargs | ||
|
||
def show(self): | ||
local_critical( | ||
*self.messages, | ||
support_hint=self.support_hint, | ||
ret_code=self.ret_code, | ||
**self.kwargs, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters