openbb-cli 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openbb_cli/__init__.py +1 -0
- openbb_cli/argparse_translator/__init__.py +0 -0
- openbb_cli/argparse_translator/argparse_class_processor.py +148 -0
- openbb_cli/argparse_translator/argparse_translator.py +627 -0
- openbb_cli/argparse_translator/obbject_registry.py +94 -0
- openbb_cli/assets/routines/routine_example.openbb +21 -0
- openbb_cli/assets/styles/default/Consolas.ttf +0 -0
- openbb_cli/assets/styles/default/dark.mpfstyle.json +47 -0
- openbb_cli/assets/styles/default/dark.mplrc.json +7 -0
- openbb_cli/assets/styles/default/dark.mplstyle +96 -0
- openbb_cli/assets/styles/default/dark.pltstyle.json +132 -0
- openbb_cli/assets/styles/default/dark.richstyle.json +9 -0
- openbb_cli/assets/styles/default/light.mpfstyle.json +47 -0
- openbb_cli/assets/styles/default/light.mplrc.json +7 -0
- openbb_cli/assets/styles/default/light.mplstyle +95 -0
- openbb_cli/assets/styles/default/light.pltstyle.json +871 -0
- openbb_cli/assets/styles/default/light.richstyle.json +9 -0
- openbb_cli/assets/styles/default/tables.pltstyle.json +102 -0
- openbb_cli/assets/styles/user/openbb.richstyle.json +9 -0
- openbb_cli/cli.py +20 -0
- openbb_cli/config/__init__.py +1 -0
- openbb_cli/config/completer.py +427 -0
- openbb_cli/config/console.py +93 -0
- openbb_cli/config/constants.py +80 -0
- openbb_cli/config/menu_text.py +165 -0
- openbb_cli/config/setup.py +11 -0
- openbb_cli/config/style.py +108 -0
- openbb_cli/controllers/base_controller.py +941 -0
- openbb_cli/controllers/base_platform_controller.py +349 -0
- openbb_cli/controllers/choices.py +324 -0
- openbb_cli/controllers/cli_controller.py +946 -0
- openbb_cli/controllers/hub_service.py +107 -0
- openbb_cli/controllers/platform_controller_factory.py +58 -0
- openbb_cli/controllers/script_parser.py +488 -0
- openbb_cli/controllers/settings_controller.py +373 -0
- openbb_cli/controllers/utils.py +967 -0
- openbb_cli/models/settings.py +73 -0
- openbb_cli/session.py +92 -0
- openbb_cli-1.0.0.dist-info/METADATA +91 -0
- openbb_cli-1.0.0.dist-info/RECORD +42 -0
- openbb_cli-1.0.0.dist-info/WHEEL +4 -0
- openbb_cli-1.0.0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"""Settings Controller Module."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
from openbb_cli.config.constants import AVAILABLE_FLAIRS
|
|
7
|
+
from openbb_cli.config.menu_text import MenuText
|
|
8
|
+
|
|
9
|
+
# pylint: disable=too-many-lines,no-member,too-many-public-methods,C0302
|
|
10
|
+
# pylint:disable=import-outside-toplevel
|
|
11
|
+
from openbb_cli.controllers.base_controller import BaseController
|
|
12
|
+
from openbb_cli.controllers.utils import all_timezones, is_timezone_valid
|
|
13
|
+
from openbb_cli.session import Session
|
|
14
|
+
|
|
15
|
+
session = Session()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class SettingsController(BaseController):
|
|
19
|
+
"""Settings Controller class."""
|
|
20
|
+
|
|
21
|
+
CHOICES_COMMANDS: List[str] = [
|
|
22
|
+
"interactive",
|
|
23
|
+
"cls",
|
|
24
|
+
"promptkit",
|
|
25
|
+
"exithelp",
|
|
26
|
+
"rcontext",
|
|
27
|
+
"richpanel",
|
|
28
|
+
"tbhint",
|
|
29
|
+
"overwrite",
|
|
30
|
+
"version",
|
|
31
|
+
"console_style",
|
|
32
|
+
"flair",
|
|
33
|
+
"timezone",
|
|
34
|
+
"n_rows",
|
|
35
|
+
"n_cols",
|
|
36
|
+
"obbject_msg",
|
|
37
|
+
"obbject_res",
|
|
38
|
+
"obbject_display",
|
|
39
|
+
]
|
|
40
|
+
PATH = "/settings/"
|
|
41
|
+
CHOICES_GENERATION = True
|
|
42
|
+
|
|
43
|
+
def __init__(self, queue: Optional[List[str]] = None):
|
|
44
|
+
"""Initialize the Constructor."""
|
|
45
|
+
super().__init__(queue)
|
|
46
|
+
|
|
47
|
+
self.update_completer(self.choices_default)
|
|
48
|
+
|
|
49
|
+
def print_help(self):
|
|
50
|
+
"""Print help."""
|
|
51
|
+
settings = session.settings
|
|
52
|
+
|
|
53
|
+
mt = MenuText("settings/")
|
|
54
|
+
mt.add_info("Feature flags")
|
|
55
|
+
mt.add_setting(
|
|
56
|
+
"interactive",
|
|
57
|
+
settings.USE_INTERACTIVE_DF,
|
|
58
|
+
description="open dataframes in interactive window",
|
|
59
|
+
)
|
|
60
|
+
mt.add_setting(
|
|
61
|
+
"cls",
|
|
62
|
+
settings.USE_CLEAR_AFTER_CMD,
|
|
63
|
+
description="clear console after each command",
|
|
64
|
+
)
|
|
65
|
+
mt.add_setting(
|
|
66
|
+
"promptkit",
|
|
67
|
+
settings.USE_PROMPT_TOOLKIT,
|
|
68
|
+
description="enable prompt toolkit (autocomplete and history)",
|
|
69
|
+
)
|
|
70
|
+
mt.add_setting(
|
|
71
|
+
"exithelp",
|
|
72
|
+
settings.ENABLE_EXIT_AUTO_HELP,
|
|
73
|
+
description="automatically print help when quitting menu",
|
|
74
|
+
)
|
|
75
|
+
mt.add_setting(
|
|
76
|
+
"rcontext",
|
|
77
|
+
settings.REMEMBER_CONTEXTS,
|
|
78
|
+
description="remember contexts between menus",
|
|
79
|
+
)
|
|
80
|
+
mt.add_setting(
|
|
81
|
+
"richpanel",
|
|
82
|
+
settings.ENABLE_RICH_PANEL,
|
|
83
|
+
description="colorful rich CLI panel",
|
|
84
|
+
)
|
|
85
|
+
mt.add_setting(
|
|
86
|
+
"tbhint",
|
|
87
|
+
settings.TOOLBAR_HINT,
|
|
88
|
+
description="displays usage hints in the bottom toolbar",
|
|
89
|
+
)
|
|
90
|
+
mt.add_setting(
|
|
91
|
+
"overwrite",
|
|
92
|
+
settings.FILE_OVERWRITE,
|
|
93
|
+
description="whether to overwrite Excel files if they already exists",
|
|
94
|
+
)
|
|
95
|
+
mt.add_setting(
|
|
96
|
+
"version",
|
|
97
|
+
settings.SHOW_VERSION,
|
|
98
|
+
description="whether to show the version in the bottom right corner",
|
|
99
|
+
)
|
|
100
|
+
mt.add_setting(
|
|
101
|
+
"obbject_msg",
|
|
102
|
+
settings.SHOW_MSG_OBBJECT_REGISTRY,
|
|
103
|
+
description="show obbject registry message after a new result is added",
|
|
104
|
+
)
|
|
105
|
+
mt.add_raw("\n")
|
|
106
|
+
mt.add_info("Preferences")
|
|
107
|
+
mt.add_cmd("console_style", description="apply a custom rich style to the CLI")
|
|
108
|
+
mt.add_cmd("flair", description="choose flair icon")
|
|
109
|
+
mt.add_cmd("timezone", description="pick timezone")
|
|
110
|
+
mt.add_cmd(
|
|
111
|
+
"n_rows", description="number of rows to show on non interactive tables"
|
|
112
|
+
)
|
|
113
|
+
mt.add_cmd(
|
|
114
|
+
"n_cols", description="number of columns to show on non interactive tables"
|
|
115
|
+
)
|
|
116
|
+
mt.add_cmd(
|
|
117
|
+
"obbject_res",
|
|
118
|
+
description="define the maximum number of obbjects allowed in the registry",
|
|
119
|
+
)
|
|
120
|
+
mt.add_cmd(
|
|
121
|
+
"obbject_display",
|
|
122
|
+
description="define the maximum number of cached results to display on the help menu",
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
session.console.print(text=mt.menu_text, menu="Settings")
|
|
126
|
+
|
|
127
|
+
def call_overwrite(self, _):
|
|
128
|
+
"""Process overwrite command."""
|
|
129
|
+
session.settings.set_item("FILE_OVERWRITE", not session.settings.FILE_OVERWRITE)
|
|
130
|
+
|
|
131
|
+
def call_version(self, _):
|
|
132
|
+
"""Process version command."""
|
|
133
|
+
session.settings.SHOW_VERSION = not session.settings.SHOW_VERSION
|
|
134
|
+
|
|
135
|
+
def call_interactive(self, _):
|
|
136
|
+
"""Process interactive command."""
|
|
137
|
+
session.settings.set_item(
|
|
138
|
+
"USE_INTERACTIVE_DF", not session.settings.USE_INTERACTIVE_DF
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
def call_cls(self, _):
|
|
142
|
+
"""Process cls command."""
|
|
143
|
+
session.settings.set_item(
|
|
144
|
+
"USE_CLEAR_AFTER_CMD", not session.settings.USE_CLEAR_AFTER_CMD
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
def call_promptkit(self, _):
|
|
148
|
+
"""Process promptkit command."""
|
|
149
|
+
session.settings.set_item(
|
|
150
|
+
"USE_PROMPT_TOOLKIT", not session.settings.USE_PROMPT_TOOLKIT
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
def call_exithelp(self, _):
|
|
154
|
+
"""Process exithelp command."""
|
|
155
|
+
session.settings.set_item(
|
|
156
|
+
"ENABLE_EXIT_AUTO_HELP", not session.settings.ENABLE_EXIT_AUTO_HELP
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
def call_rcontext(self, _):
|
|
160
|
+
"""Process rcontext command."""
|
|
161
|
+
session.settings.set_item(
|
|
162
|
+
"REMEMBER_CONTEXTS", not session.settings.REMEMBER_CONTEXTS
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
def call_dt(self, _):
|
|
166
|
+
"""Process dt command."""
|
|
167
|
+
session.settings.set_item("USE_DATETIME", not session.settings.USE_DATETIME)
|
|
168
|
+
|
|
169
|
+
def call_richpanel(self, _):
|
|
170
|
+
"""Process richpanel command."""
|
|
171
|
+
session.settings.set_item(
|
|
172
|
+
"ENABLE_RICH_PANEL", not session.settings.ENABLE_RICH_PANEL
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
def call_tbhint(self, _):
|
|
176
|
+
"""Process tbhint command."""
|
|
177
|
+
if session.settings.TOOLBAR_HINT:
|
|
178
|
+
session.console.print("Will take effect when running CLI again.")
|
|
179
|
+
session.settings.set_item("TOOLBAR_HINT", not session.settings.TOOLBAR_HINT)
|
|
180
|
+
|
|
181
|
+
def call_obbject_msg(self, _):
|
|
182
|
+
"""Process obbject_msg command."""
|
|
183
|
+
session.settings.set_item(
|
|
184
|
+
"SHOW_MSG_OBBJECT_REGISTRY",
|
|
185
|
+
not session.settings.SHOW_MSG_OBBJECT_REGISTRY,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
def call_console_style(self, other_args: List[str]) -> None:
|
|
189
|
+
"""Process cosole_style command."""
|
|
190
|
+
parser = argparse.ArgumentParser(
|
|
191
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
192
|
+
prog="console_style",
|
|
193
|
+
description="Change your custom console style.",
|
|
194
|
+
add_help=False,
|
|
195
|
+
)
|
|
196
|
+
parser.add_argument(
|
|
197
|
+
"-s",
|
|
198
|
+
"--style",
|
|
199
|
+
dest="style",
|
|
200
|
+
action="store",
|
|
201
|
+
required=False,
|
|
202
|
+
choices=session.style.available_styles,
|
|
203
|
+
)
|
|
204
|
+
ns_parser = self.parse_simple_args(parser, other_args)
|
|
205
|
+
|
|
206
|
+
if ns_parser and ns_parser.style:
|
|
207
|
+
session.style.apply(ns_parser.style)
|
|
208
|
+
session.settings.set_item("RICH_STYLE", ns_parser.style)
|
|
209
|
+
elif not other_args:
|
|
210
|
+
session.console.print(
|
|
211
|
+
f"Current console style: {session.settings.RICH_STYLE}"
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
def call_flair(self, other_args: List[str]) -> None:
|
|
215
|
+
"""Process flair command."""
|
|
216
|
+
parser = argparse.ArgumentParser(
|
|
217
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
218
|
+
prog="flair",
|
|
219
|
+
description="Change your custom flair.",
|
|
220
|
+
add_help=False,
|
|
221
|
+
)
|
|
222
|
+
parser.add_argument(
|
|
223
|
+
"-f",
|
|
224
|
+
"--flair",
|
|
225
|
+
dest="flair",
|
|
226
|
+
action="store",
|
|
227
|
+
required=False,
|
|
228
|
+
choices=list(AVAILABLE_FLAIRS.keys()),
|
|
229
|
+
)
|
|
230
|
+
ns_parser = self.parse_simple_args(parser, other_args)
|
|
231
|
+
|
|
232
|
+
if ns_parser and ns_parser.flair:
|
|
233
|
+
session.settings.set_item("FLAIR", ns_parser.flair)
|
|
234
|
+
elif not other_args:
|
|
235
|
+
session.console.print(f"Current flair: {session.settings.FLAIR}")
|
|
236
|
+
|
|
237
|
+
def call_timezone(self, other_args: List[str]) -> None:
|
|
238
|
+
"""Process timezone command."""
|
|
239
|
+
parser = argparse.ArgumentParser(
|
|
240
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
241
|
+
prog="timezone",
|
|
242
|
+
description="Change your custom timezone.",
|
|
243
|
+
add_help=False,
|
|
244
|
+
)
|
|
245
|
+
parser.add_argument(
|
|
246
|
+
"-t",
|
|
247
|
+
"--timezone",
|
|
248
|
+
dest="timezone",
|
|
249
|
+
action="store",
|
|
250
|
+
required=False,
|
|
251
|
+
type=str,
|
|
252
|
+
choices=all_timezones,
|
|
253
|
+
)
|
|
254
|
+
ns_parser = self.parse_simple_args(parser, other_args)
|
|
255
|
+
|
|
256
|
+
if ns_parser and ns_parser.timezone:
|
|
257
|
+
if is_timezone_valid(ns_parser.timezone):
|
|
258
|
+
session.settings.set_item("TIMEZONE", ns_parser.timezone)
|
|
259
|
+
else:
|
|
260
|
+
session.console.print(
|
|
261
|
+
"Invalid timezone. Please enter a valid timezone."
|
|
262
|
+
)
|
|
263
|
+
session.console.print(
|
|
264
|
+
f"Available timezones are: {', '.join(all_timezones)}"
|
|
265
|
+
)
|
|
266
|
+
elif not other_args:
|
|
267
|
+
session.console.print(f"Current timezone: {session.settings.TIMEZONE}")
|
|
268
|
+
|
|
269
|
+
def call_n_rows(self, other_args: List[str]) -> None:
|
|
270
|
+
"""Process n_rows command."""
|
|
271
|
+
parser = argparse.ArgumentParser(
|
|
272
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
273
|
+
prog="n_rows",
|
|
274
|
+
description="Number of rows to show (when not using interactive tables).",
|
|
275
|
+
add_help=False,
|
|
276
|
+
)
|
|
277
|
+
parser.add_argument(
|
|
278
|
+
"-r",
|
|
279
|
+
"--rows",
|
|
280
|
+
dest="rows",
|
|
281
|
+
action="store",
|
|
282
|
+
required=False,
|
|
283
|
+
type=int,
|
|
284
|
+
)
|
|
285
|
+
ns_parser = self.parse_simple_args(parser, other_args)
|
|
286
|
+
|
|
287
|
+
if ns_parser and ns_parser.rows:
|
|
288
|
+
session.settings.set_item("ALLOWED_NUMBER_OF_ROWS", ns_parser.rows)
|
|
289
|
+
|
|
290
|
+
elif not other_args:
|
|
291
|
+
session.console.print(
|
|
292
|
+
f"Current number of rows: {session.settings.ALLOWED_NUMBER_OF_ROWS}"
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
def call_n_cols(self, other_args: List[str]) -> None:
|
|
296
|
+
"""Process n_cols command."""
|
|
297
|
+
parser = argparse.ArgumentParser(
|
|
298
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
299
|
+
prog="n_cols",
|
|
300
|
+
description="Number of columns to show (when not using interactive tables).",
|
|
301
|
+
add_help=False,
|
|
302
|
+
)
|
|
303
|
+
parser.add_argument(
|
|
304
|
+
"-c",
|
|
305
|
+
"--columns",
|
|
306
|
+
dest="columns",
|
|
307
|
+
action="store",
|
|
308
|
+
required=False,
|
|
309
|
+
type=int,
|
|
310
|
+
)
|
|
311
|
+
ns_parser = self.parse_simple_args(parser, other_args)
|
|
312
|
+
|
|
313
|
+
if ns_parser and ns_parser.columns:
|
|
314
|
+
session.settings.set_item("ALLOWED_NUMBER_OF_COLUMNS", ns_parser.columns)
|
|
315
|
+
|
|
316
|
+
elif not other_args:
|
|
317
|
+
session.console.print(
|
|
318
|
+
f"Current number of columns: {session.settings.ALLOWED_NUMBER_OF_COLUMNS}"
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
def call_obbject_res(self, other_args: List[str]):
|
|
322
|
+
"""Process obbject_res command."""
|
|
323
|
+
parser = argparse.ArgumentParser(
|
|
324
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
325
|
+
prog="obbject_res",
|
|
326
|
+
description="Maximum allowed number of results to keep in the OBBject Registry.",
|
|
327
|
+
add_help=False,
|
|
328
|
+
)
|
|
329
|
+
parser.add_argument(
|
|
330
|
+
"-n",
|
|
331
|
+
"--number",
|
|
332
|
+
dest="number",
|
|
333
|
+
action="store",
|
|
334
|
+
required=False,
|
|
335
|
+
type=int,
|
|
336
|
+
)
|
|
337
|
+
ns_parser = self.parse_simple_args(parser, other_args)
|
|
338
|
+
|
|
339
|
+
if ns_parser and ns_parser.number:
|
|
340
|
+
session.settings.set_item("N_TO_KEEP_OBBJECT_REGISTRY", ns_parser.number)
|
|
341
|
+
|
|
342
|
+
elif not other_args:
|
|
343
|
+
session.console.print(
|
|
344
|
+
f"Current maximum allowed number of results to keep in the OBBject registry:"
|
|
345
|
+
f" {session.settings.N_TO_KEEP_OBBJECT_REGISTRY}"
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
def call_obbject_display(self, other_args: List[str]):
|
|
349
|
+
"""Process obbject_display command."""
|
|
350
|
+
parser = argparse.ArgumentParser(
|
|
351
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
352
|
+
prog="obbject_display",
|
|
353
|
+
description="Number of results to display from the OBBject Registry.",
|
|
354
|
+
add_help=False,
|
|
355
|
+
)
|
|
356
|
+
parser.add_argument(
|
|
357
|
+
"-n",
|
|
358
|
+
"--number",
|
|
359
|
+
dest="number",
|
|
360
|
+
action="store",
|
|
361
|
+
required=False,
|
|
362
|
+
type=int,
|
|
363
|
+
)
|
|
364
|
+
ns_parser = self.parse_simple_args(parser, other_args)
|
|
365
|
+
|
|
366
|
+
if ns_parser and ns_parser.number:
|
|
367
|
+
session.settings.set_item("N_TO_DISPLAY_OBBJECT_REGISTRY", ns_parser.number)
|
|
368
|
+
|
|
369
|
+
elif not other_args:
|
|
370
|
+
session.console.print(
|
|
371
|
+
f"Current number of results to display from the OBBject registry:"
|
|
372
|
+
f" {session.settings.N_TO_DISPLAY_OBBJECT_REGISTRY}"
|
|
373
|
+
)
|