forked from Kanaries/pygwalker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpygwalker_command.py
114 lines (93 loc) · 2.75 KB
/
pygwalker_command.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from typing import Tuple
import argparse
from pygwalker.services.config import (
reset_all_config,
set_config,
get_config_params_help,
reset_config,
get_all_config_str,
CONFIG_PATH
)
from pygwalker.services.kanaries_cli_login import kanaries_login
parser = argparse.ArgumentParser(
prog="pygwalker",
description='PyGWalker: Combining Jupyter Notebook with a Tableau-like UI'
)
subparsers = parser.add_subparsers(dest='command')
# config command
config_parser = subparsers.add_parser(
'config',
help=f'Modify configuration file. (default: {CONFIG_PATH})',
add_help=True,
description=f'Modify configuration file. (default: {CONFIG_PATH}) \n' + get_config_params_help(),
formatter_class=argparse.RawTextHelpFormatter
)
config_parser.add_argument(
'--set',
nargs='*',
metavar='key=value',
help='Set configuration. e.g. "pygwalker config --set privacy=update-only"'
)
config_parser.add_argument(
'--reset',
nargs='*',
metavar='key',
help='Reset user configuration and use default values instead. e.g. "pygwalker config --reset privacy"'
)
config_parser.add_argument(
'--reset-all',
action='store_true',
help='Reset all user configuration and use default values instead. e.g. "pygwalker config --reset-all"'
)
config_parser.add_argument(
'--list',
action='store_true',
help='List current used configuration.'
)
# login command
login_parser = subparsers.add_parser(
'login',
help="set up your kanaries token via kanaries website authorization.",
add_help=True,
description="set up your kanaries token via kanaries website authorization.",
formatter_class=argparse.RawTextHelpFormatter
)
def command_set_config(value: Tuple[str]):
config = dict(
item.split('=')
for item in value
)
set_config(config)
def command_reset_config(value: Tuple[str]):
reset_config(value)
def command_reset_all_config(_):
reset_all_config()
def command_list_config(_):
config = get_all_config_str()
print("Current configuration:")
print(config)
def main():
conifg_command_list = [
("set", command_set_config),
("reset", command_reset_config),
("reset_all", command_reset_all_config),
("list", command_list_config)
]
args = parser.parse_args()
if args.command is None:
parser.print_help()
return
if args.command == 'config':
for action, action_func in conifg_command_list:
value = getattr(args, action)
if value:
action_func(value)
return
config_parser.print_help()
return
if args.command == 'login':
kanaries_login()
return
parser.print_help()
if __name__ == '__main__':
main()