Skip to content

Commit

Permalink
Fix crypto/disc/top sort (#4167)
Browse files Browse the repository at this point in the history
* fix sort choices

* fix unit tests
  • Loading branch information
montezdesousa authored Feb 8, 2023
1 parent 1e1f19e commit 93dd0bc
Show file tree
Hide file tree
Showing 4 changed files with 2,468 additions and 2,708 deletions.
21 changes: 14 additions & 7 deletions openbb_terminal/cryptocurrency/discovery/discovery_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
)
from openbb_terminal.custom_prompt_toolkit import NestedCompleter
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import EXPORT_ONLY_RAW_DATA_ALLOWED, check_positive
from openbb_terminal.helper_funcs import (
EXPORT_ONLY_RAW_DATA_ALLOWED,
check_positive,
)
from openbb_terminal.menu import session
from openbb_terminal.parent_classes import BaseController
from openbb_terminal.rich_config import MenuText, console, get_ordered_list_sources
Expand Down Expand Up @@ -52,6 +55,16 @@ def __init__(self, queue: List[str] = None):
if session and obbff.USE_PROMPT_TOOLKIT:
choices: dict = self.choices_default

ordered_list_sources_top = get_ordered_list_sources(f"{self.PATH}top")
if ordered_list_sources_top and ordered_list_sources_top[0] == "CoinGecko":
choices["top"]["--sort"] = {
c: {} for c in pycoingecko_view.COINS_COLUMNS
}
else:
choices["top"]["--sort"] = {c: {} for c in coinmarketcap_model.FILTERS}

choices["top"]["-s"] = choices["top"]["--sort"]

self.completer = NestedCompleter.from_nested_dict(choices)

def print_help(self):
Expand All @@ -78,11 +91,6 @@ def call_top(self, other_args):
else:
argument_sort_default = "CMC_Rank"

if ordered_list_sources_top and ordered_list_sources_top[0] == "CoinGecko":
argument_sort_choices = pycoingecko_view.COINS_COLUMNS
else:
argument_sort_choices = coinmarketcap_model.FILTERS

parser = argparse.ArgumentParser(
prog="top",
add_help=False,
Expand Down Expand Up @@ -121,7 +129,6 @@ def call_top(self, other_args):
nargs="+",
help="Sort by given column. Default: Market Cap Rank",
default=argument_sort_default,
choices=argument_sort_choices,
metavar="SORTBY",
)
parser.add_argument(
Expand Down
Loading

0 comments on commit 93dd0bc

Please sign in to comment.