Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad api output #2659

Merged
merged 3 commits into from
Sep 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions openbb_terminal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import types
import functools
import importlib
from typing import Optional, Callable
from typing import Optional, Callable, List

from openbb_terminal.helper_classes import TerminalStyle # noqa: F401
from openbb_terminal import helper_funcs as helper # noqa: F401
Expand Down Expand Up @@ -2065,20 +2065,23 @@ def settings(self):
def load_menus(self):
"""Creates the API structure (see openbb.stocks.command) by setting attributes and saving the functions"""

def menu_message(menu: str, function_map: dict):
def menu_message(menu: str, full_path: List[str], function_map: dict):
"""Creates a callable function, which prints a menus help message
Parameters
----------
menu: str
Menu for which the help message is generated
full_path: List[str]
The list to get to the path
function_map: dict
Dictionary with the functions and their virtual paths
Returns
-------
Callable:
Function which prints help message
"""
filtered_dict = {k: v for (k, v) in function_map.items() if menu in k}
path_str = ".".join(full_path)
filtered_dict = {k: v for (k, v) in function_map.items() if path_str in k}

def f():
string = menu.upper() + " Menu\n\nThe api commands of the the menu:"
Expand All @@ -2099,7 +2102,12 @@ def f():

for menu in virtual_path_split[:-1]:
if not hasattr(previous_menu, menu):
next_menu = MenuFiller(function=menu_message(menu, function_map))
partial_path = virtual_path_split[
: virtual_path_split.index(menu) + 1
]
next_menu = MenuFiller(
function=menu_message(menu, partial_path, function_map)
)
setattr(previous_menu, menu, next_menu)
previous_menu = getattr(previous_menu, menu)
setattr(previous_menu, last_virtual_path, function)
Expand Down