FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-tools/voidpp_tools/cli_utils.py at master · voidpp/python-tools · GitHub
voidpp
/
python-tools
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
3
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-tools
/
voidpp_tools
/
cli_utils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (21 loc) · 865 Bytes
Breadcrumbs
python-tools
/
voidpp_tools
/
cli_utils.py
Copy path
File metadata and controls
29 lines (21 loc) · 865 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from
functools
import
wraps
def
confirm_prompt
(
msg
=
"Are you sure?"
,
help
=
"(ok: enter, cancel: ctrl+c)"
):
try
:
raw_input
(
"{} {} "
.
format
(
msg
,
help
))
return
True
except
KeyboardInterrupt
:
# for new line
print
(
'
\n
Cancelled'
)
return
False
def
get_func_defaults
(
func
):
diff
=
len
(
func
.
func_code
.
co_varnames
)
-
len
(
func
.
func_defaults
)
return
{
func
.
func_code
.
co_varnames
[
diff
+
idx
]:
val
for
idx
,
val
in
enumerate
(
func
.
func_defaults
)}
def
confirm
(
msg
=
get_func_defaults
(
confirm_prompt
)[
'msg'
],
help
=
get_func_defaults
(
confirm_prompt
)[
'help'
]):
def
decor
(
func
):
@
wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
if
not
kwargs
.
get
(
'iamsure'
,
False
)
and
not
confirm_prompt
(
msg
,
help
):
return
func
(
*
args
,
**
kwargs
)
return
wrapper
return
decor
Back
|
FazBrowse Home
|
New Git URL