From 7917ce30d1fbac795d910d1303dfe780877c88ad Mon Sep 17 00:00:00 2001 From: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Date: Mon, 6 Mar 2023 13:56:57 +0000 Subject: [PATCH] fix country choices (#4403) --- openbb_terminal/helper_funcs.py | 5 +++++ .../mutual_funds/mutual_fund_controller.py | 20 +++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/openbb_terminal/helper_funcs.py b/openbb_terminal/helper_funcs.py index c8ab2ccc3c1..9d7a0ae8be8 100644 --- a/openbb_terminal/helper_funcs.py +++ b/openbb_terminal/helper_funcs.py @@ -657,6 +657,11 @@ def valid_hour(hr: str) -> int: return new_hr +def lower_str(string: str) -> str: + """Convert string to lowercase.""" + return string.lower() + + def us_market_holidays(years) -> list: """Get US market holidays.""" if isinstance(years, int): diff --git a/openbb_terminal/mutual_funds/mutual_fund_controller.py b/openbb_terminal/mutual_funds/mutual_fund_controller.py index 8d4fca6bd98..e6ca90744a5 100644 --- a/openbb_terminal/mutual_funds/mutual_fund_controller.py +++ b/openbb_terminal/mutual_funds/mutual_fund_controller.py @@ -15,6 +15,7 @@ from openbb_terminal.decorators import log_start_end from openbb_terminal.helper_funcs import ( EXPORT_ONLY_FIGURES_ALLOWED, check_positive, + lower_str, valid_date, ) from openbb_terminal.menu import session @@ -79,7 +80,7 @@ class FundController(BaseController): mt = MenuText("funds/") mt.add_cmd("country") mt.add_raw("\n") - mt.add_param("_country", self.country.title()) + mt.add_param("_country", self.country) mt.add_raw("\n") mt.add_cmd("search") mt.add_cmd("load") @@ -181,29 +182,26 @@ class FundController(BaseController): add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="country", - description="Set a country for funds", + description="Set a country for funds.", ) parser.add_argument( "-n", "--name", - type=str, + type=lower_str, choices=self.fund_countries, dest="name", help="country to select", - default="", + default="united_states", + metavar="NAME", ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-n") ns_parser = self.parse_known_args_and_warn(parser, other_args) if ns_parser: - country_candidate = ns_parser.name - if country_candidate.lower() in self.fund_countries: + country_candidate = ns_parser.name.lower() + if country_candidate in self.fund_countries: self.country = country_candidate - console.print(f"{country_candidate.title()} selected.") - else: - console.print( - f'" {country_candidate.title()} " not a valid country to select.' - ) + console.print(f"'{country_candidate}' selected.") return self.queue