From 4f1430f8e3fb244c8cc44b0ea9a84cc4e73c1d9b Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Thu, 6 Jun 2024 02:51:00 -0400 Subject: [PATCH 1/3] Remove clusters list and change to user typed input --- linodecli/plugins/obj/__init__.py | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/linodecli/plugins/obj/__init__.py b/linodecli/plugins/obj/__init__.py index 97450002..35e2125d 100644 --- a/linodecli/plugins/obj/__init__.py +++ b/linodecli/plugins/obj/__init__.py @@ -18,7 +18,7 @@ from linodecli.cli import CLI from linodecli.configuration import _do_get_request -from linodecli.configuration.helpers import _default_thing_input +from linodecli.configuration.helpers import _default_text_input from linodecli.plugins import PluginContext, inherit_plugin_args from linodecli.plugins.obj.buckets import create_bucket, delete_bucket from linodecli.plugins.obj.config import ( @@ -62,18 +62,6 @@ HAS_BOTO = False -def get_available_cluster(cli: CLI): - """Get list of possible clusters for the account""" - return [ - c["id"] - for c in _do_get_request( # pylint: disable=protected-access - cli.config.base_url, - "/object-storage/clusters", - token=cli.config.get_token(), - )["data"] - ] - - def generate_url(get_client, args, **kwargs): # pylint: disable=unused-argument """ Generates a URL to an object @@ -290,7 +278,7 @@ def print_help(parser: ArgumentParser): print("See --help for individual commands for more information") -def get_obj_args_parser(clusters: List[str]): +def get_obj_args_parser(): """ Initialize and return the argument parser for the obj plug-in. """ @@ -307,7 +295,6 @@ def get_obj_args_parser(clusters: List[str]): "--cluster", metavar="CLUSTER", type=str, - choices=clusters, help="The cluster to use for the operation", ) @@ -369,8 +356,7 @@ def call( sys.exit(2) # requirements not met - we can't go on - clusters = get_available_cluster(context.client) if not is_help else None - parser = get_obj_args_parser(clusters) + parser = get_obj_args_parser() parsed, args = parser.parse_known_args(args) # don't mind --no-defaults if it's there; the top-level parser already took care of it @@ -553,15 +539,12 @@ def _configure_plugin(client: CLI): """ Configures a default cluster value. """ - clusters = get_available_cluster(client) - cluster = _default_thing_input( # pylint: disable=protected-access + cluster = _default_text_input( # pylint: disable=protected-access "Configure a default Cluster for operations.", - clusters, - "Default Cluster: ", - "Please select a valid Cluster", - optional=False, # this is the only configuration right now + optional=True, ) - client.config.plugin_set_value("cluster", cluster) + if cluster: + client.config.plugin_set_value("cluster", cluster) client.config.write_config() From a750797b6f45922d7565d39732cf9b037a6b03c1 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Thu, 6 Jun 2024 02:56:20 -0400 Subject: [PATCH 2/3] Fix unit test --- tests/unit/test_plugin_obj.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_plugin_obj.py b/tests/unit/test_plugin_obj.py index 22dfaae3..17ae5c42 100644 --- a/tests/unit/test_plugin_obj.py +++ b/tests/unit/test_plugin_obj.py @@ -5,7 +5,7 @@ def test_print_help(mock_cli: CLI, capsys: CaptureFixture): - parser = get_obj_args_parser(["us-mia-1"]) + parser = get_obj_args_parser() print_help(parser) captured_text = capsys.readouterr() assert parser.format_help() in captured_text.out From 1c3c8f14d02dbb929c0fa259a3fc4fa0af193850 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang <121905282+zliang-akamai@users.noreply.github.com> Date: Thu, 6 Jun 2024 14:48:15 -0400 Subject: [PATCH 3/3] Update wording for default text input Co-authored-by: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com> --- linodecli/plugins/obj/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linodecli/plugins/obj/__init__.py b/linodecli/plugins/obj/__init__.py index 35e2125d..18f84df7 100644 --- a/linodecli/plugins/obj/__init__.py +++ b/linodecli/plugins/obj/__init__.py @@ -541,7 +541,7 @@ def _configure_plugin(client: CLI): """ cluster = _default_text_input( # pylint: disable=protected-access - "Configure a default Cluster for operations.", + "Default cluster for operations (e.g. `us-mia-1`)", optional=True, )