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

Change Clusters Choice in OBJ Plugin Config to be Text Input #618

Merged
Show file tree
Hide file tree
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
35 changes: 9 additions & 26 deletions linodecli/plugins/obj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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",
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
"Configure a default Cluster for operations.",
clusters,
"Default Cluster: ",
"Please select a valid Cluster",
optional=False, # this is the only configuration right now

cluster = _default_text_input( # pylint: disable=protected-access
"Default cluster for operations (e.g. `us-mia-1`)",
optional=True,
)

client.config.plugin_set_value("cluster", cluster)
if cluster:
client.config.plugin_set_value("cluster", cluster)
client.config.write_config()
2 changes: 1 addition & 1 deletion tests/unit/test_plugin_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading