Skip to content

Commit

Permalink
Merge pull request #965 from sirosen/improve-display-api
Browse files Browse the repository at this point in the history
Improve the internal output display API
  • Loading branch information
sirosen authored Mar 8, 2024
2 parents bc5fae1 + 4779f6d commit 19b2a18
Show file tree
Hide file tree
Showing 95 changed files with 232 additions and 257 deletions.
6 changes: 3 additions & 3 deletions src/globus_cli/commands/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import click

from globus_cli.termio import TextMode, display
from globus_cli.termio import display

if t.TYPE_CHECKING:
from ..services.transfer import CustomTransferClient
Expand Down Expand Up @@ -59,7 +59,7 @@ def check_completed() -> bool:
# TODO: possibly update TransferClient.task_wait so that we don't
# need to do an extra fetch to get the task status after completion
res = transfer_client.get_task(task_id)
display(res, text_mode=TextMode.silent)
display(res, text_mode=display.SILENT)

status = res["status"]
if status == "SUCCEEDED":
Expand Down Expand Up @@ -99,6 +99,6 @@ def check_completed() -> bool:

# output json if requested, but nothing for text mode
res = transfer_client.get_task(task_id)
display(res, text_mode=TextMode.silent)
display(res, text_mode=display.SILENT)

click.get_current_context().exit(exit_code)
4 changes: 2 additions & 2 deletions src/globus_cli/commands/bookmark/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command
from globus_cli.termio import TextMode, display
from globus_cli.termio import display

from ._common import resolve_id_or_name

Expand Down Expand Up @@ -32,4 +32,4 @@ def bookmark_delete(login_manager: LoginManager, *, bookmark_id_or_name: str) ->
bookmark_id = resolve_id_or_name(transfer_client, bookmark_id_or_name)["id"]

res = transfer_client.delete_bookmark(bookmark_id)
display(res, text_mode=TextMode.text_raw, response_key="message")
display(res, text_mode=display.RAW, response_key="message")
4 changes: 2 additions & 2 deletions src/globus_cli/commands/bookmark/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command
from globus_cli.termio import Field, TextMode, display, is_verbose
from globus_cli.termio import Field, display, is_verbose

from ._common import resolve_id_or_name

Expand Down Expand Up @@ -46,7 +46,7 @@ def bookmark_show(login_manager: LoginManager, *, bookmark_id_or_name: str) -> N
res = resolve_id_or_name(transfer_client, bookmark_id_or_name)
display(
res,
text_mode=TextMode.text_record,
text_mode=display.RECORD,
fields=[
Field("ID", "id"),
Field("Name", "name"),
Expand Down
6 changes: 3 additions & 3 deletions src/globus_cli/commands/cli_profile_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from globus_cli.login_manager import is_client_login, token_storage_adapter
from globus_cli.parsing import command
from globus_cli.termio import Field, TextMode, display, formatters
from globus_cli.termio import Field, display, formatters


def _profilestr_to_datadict(s: str) -> dict[str, t.Any] | None:
Expand Down Expand Up @@ -97,7 +97,7 @@ def cli_profile_list(*, all: bool) -> None:
]
if all:
fields.append(Field("GLOBUS_SDK_ENVIRONMENT", "env"))
display(user_profiles, text_mode=TextMode.text_table, fields=fields)
display(user_profiles, text_mode=display.TABLE, fields=fields)
if client_profiles:
click.echo("")
fields = [
Expand All @@ -106,4 +106,4 @@ def cli_profile_list(*, all: bool) -> None:
]
if all:
fields.append(Field("GLOBUS_SDK_ENVIRONMENT", "env"))
display(client_profiles, text_mode=TextMode.text_table, fields=fields)
display(client_profiles, text_mode=display.TABLE, fields=fields)
4 changes: 2 additions & 2 deletions src/globus_cli/commands/collection/create/guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from globus_cli.login_manager.context import LoginContext
from globus_cli.parsing import command, endpointish_params, mutex_option_group
from globus_cli.services.gcs import CustomGCSClient
from globus_cli.termio import TextMode, display
from globus_cli.termio import display


@command("guest", short_help="Create a GCSv5 Guest Collection")
Expand Down Expand Up @@ -139,7 +139,7 @@ def collection_create_guest(
raise

fields = standard_collection_fields(login_manager.get_auth_client())
display(res, text_mode=TextMode.text_record, fields=filter_fields(fields, res))
display(res, text_mode=display.RECORD, fields=filter_fields(fields, res))


def _select_user_credential_id(
Expand Down
4 changes: 2 additions & 2 deletions src/globus_cli/commands/collection/create/mapped.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
endpointish_params,
mutex_option_group,
)
from globus_cli.termio import TextMode, display
from globus_cli.termio import display


def _make_multi_use_option_str(s: str) -> str:
Expand Down Expand Up @@ -312,6 +312,6 @@ def collection_create_mapped(
fields = standard_collection_fields(login_manager.get_auth_client())
display(
res,
text_mode=TextMode.text_record,
text_mode=display.RECORD,
fields=filter_fields(fields, res),
)
4 changes: 2 additions & 2 deletions src/globus_cli/commands/collection/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import collection_id_arg, command
from globus_cli.termio import TextMode, display
from globus_cli.termio import display


@command("delete", short_help="Delete an existing Collection")
Expand All @@ -15,4 +15,4 @@ def collection_delete(login_manager: LoginManager, *, collection_id: uuid.UUID)
"""
gcs_client = login_manager.get_gcs_client(collection_id=collection_id)
res = gcs_client.delete_collection(collection_id)
display(res, text_mode=TextMode.text_raw, response_key="code")
display(res, text_mode=display.RAW, response_key="code")
4 changes: 2 additions & 2 deletions src/globus_cli/commands/collection/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import Field, TextMode, display, formatters
from globus_cli.termio import Field, display, formatters


class ChoiceSlugified(click.Choice):
Expand Down Expand Up @@ -112,7 +112,7 @@ def collection_list(
res = gcs_client.get_collection_list(**params)
display(
res,
text_mode=TextMode.text_table,
text_mode=display.TABLE,
fields=[
Field("ID", "id"),
Field("Display Name", "display_name"),
Expand Down
4 changes: 2 additions & 2 deletions src/globus_cli/commands/collection/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from globus_cli.login_manager import LoginManager
from globus_cli.parsing import collection_id_arg, command
from globus_cli.termio import Field, TextMode, display, formatters
from globus_cli.termio import Field, display, formatters

PRIVATE_FIELDS: list[Field] = [
Field("Root Path", "root_path"),
Expand Down Expand Up @@ -64,6 +64,6 @@ def collection_show(

display(
res,
text_mode=TextMode.text_record,
text_mode=display.RECORD,
fields=real_fields,
)
4 changes: 2 additions & 2 deletions src/globus_cli/commands/collection/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
emptyable_opt_list_callback,
endpointish_params,
)
from globus_cli.termio import Field, TextMode, display
from globus_cli.termio import Field, display

_MULTI_USE_OPTION_STR = "Give this option multiple times in a single command"

Expand Down Expand Up @@ -206,5 +206,5 @@ def collection_update(
display(
res,
fields=[_FullDataField("code", "code")],
text_mode=TextMode.text_record,
text_mode=display.RECORD,
)
10 changes: 2 additions & 8 deletions src/globus_cli/commands/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
local_user_option,
task_submission_options,
)
from globus_cli.termio import (
Field,
TextMode,
display,
err_is_terminal,
term_is_interactive,
)
from globus_cli.termio import Field, display, err_is_terminal, term_is_interactive


@command(
Expand Down Expand Up @@ -189,6 +183,6 @@ def process_batch_line(path: TaskPath) -> None:
res = transfer_client.submit_delete(delete_data)
display(
res,
text_mode=TextMode.text_record,
text_mode=display.RECORD,
fields=[Field("Message", "message"), Field("Task ID", "task_id")],
)
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from globus_cli.login_manager import LoginManager, is_remote_session
from globus_cli.parsing import command, endpoint_id_arg, mutex_option_group
from globus_cli.termio import TextMode, display
from globus_cli.termio import display


@command("activate", deprecated=True, hidden=True)
Expand Down Expand Up @@ -274,4 +274,4 @@ def endpoint_activate(
)

# output
display(res, text_mode=TextMode.text_raw, response_key="message")
display(res, text_mode=display.RAW, response_key="message")
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
mutex_option_group,
one_use_option,
)
from globus_cli.termio import Field, TextMode, display, print_command_hint
from globus_cli.termio import Field, display, print_command_hint

from ._common import validate_endpoint_create_and_update_params

Expand Down Expand Up @@ -174,5 +174,5 @@ def endpoint_create(
display(
res,
fields=(COMMON_FIELDS + GCP_FIELDS if personal else COMMON_FIELDS),
text_mode=TextMode.text_record,
text_mode=display.RECORD,
)
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/deactivate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import TextMode, display
from globus_cli.termio import display


@command("deactivate", deprecated=True, hidden=True)
Expand All @@ -15,4 +15,4 @@ def endpoint_deactivate(login_manager: LoginManager, *, endpoint_id: uuid.UUID)
"""
transfer_client = login_manager.get_transfer_client()
res = transfer_client.endpoint_deactivate(endpoint_id)
display(res, text_mode=TextMode.text_raw, response_key="message")
display(res, text_mode=display.RAW, response_key="message")
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from globus_cli.endpointish import Endpointish
from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import TextMode, display
from globus_cli.termio import display


@command(
Expand All @@ -30,4 +30,4 @@ def endpoint_delete(login_manager: LoginManager, *, endpoint_id: uuid.UUID) -> N
).assert_is_traditional_endpoint()

res = transfer_client.delete_endpoint(endpoint_id)
display(res, text_mode=TextMode.text_raw, response_key="message")
display(res, text_mode=display.RAW, response_key="message")
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/permission/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import ENDPOINT_PLUS_REQPATH, command, security_principal_opts
from globus_cli.termio import Field, TextMode, display
from globus_cli.termio import Field, display


@command(
Expand Down Expand Up @@ -110,6 +110,6 @@ def create_command(
res = transfer_client.add_endpoint_acl_rule(endpoint_id, rule_data)
display(
res,
text_mode=TextMode.text_record,
text_mode=display.RECORD,
fields=[Field("Message", "message"), Field("Rule ID", "access_id")],
)
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/permission/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import TextMode, display
from globus_cli.termio import display


@command(
Expand Down Expand Up @@ -34,4 +34,4 @@ def delete_command(
transfer_client = login_manager.get_transfer_client()

res = transfer_client.delete_endpoint_acl_rule(endpoint_id, rule_id)
display(res, text_mode=TextMode.text_raw, response_key="message")
display(res, text_mode=display.RAW, response_key="message")
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/permission/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import Field, TextMode, display
from globus_cli.termio import Field, display

from ._common import AclPrincipalFormatter

Expand Down Expand Up @@ -37,7 +37,7 @@ def show_command(
rule = transfer_client.get_endpoint_acl_rule(endpoint_id, rule_id)
display(
rule,
text_mode=TextMode.text_record,
text_mode=display.RECORD,
fields=[
Field("Rule ID", "id"),
Field("Permissions", "permissions"),
Expand Down
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/permission/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import TextMode, display
from globus_cli.termio import display


@command(
Expand Down Expand Up @@ -49,4 +49,4 @@ def update_command(

rule_data = assemble_generic_doc("access", permissions=permissions)
res = transfer_client.update_endpoint_acl_rule(endpoint_id, rule_id, rule_data)
display(res, text_mode=TextMode.text_raw, response_key="message")
display(res, text_mode=display.RAW, response_key="message")
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/role/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import TextMode, display
from globus_cli.termio import display

from ._common import role_id_arg

Expand Down Expand Up @@ -34,4 +34,4 @@ def role_delete(
"""
transfer_client = login_manager.get_transfer_client()
res = transfer_client.delete_endpoint_role(endpoint_id, role_id)
display(res, text_mode=TextMode.text_raw, response_key="message")
display(res, text_mode=display.RAW, response_key="message")
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/role/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import Field, TextMode, display
from globus_cli.termio import Field, display

from ._common import RolePrincipalFormatter, role_id_arg

Expand Down Expand Up @@ -51,7 +51,7 @@ def role_show(
role = transfer_client.get_endpoint_role(endpoint_id, role_id)
display(
role,
text_mode=TextMode.text_record,
text_mode=display.RECORD,
fields=[
Field("Principal Type", "principal_type"),
Field("Principal", "@", formatter=formatter),
Expand Down
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/server/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import TextMode, display
from globus_cli.termio import display

from ._common import server_add_opts

Expand Down Expand Up @@ -64,4 +64,4 @@ def server_add(
)

res = transfer_client.add_endpoint_server(endpoint_id, server_doc)
display(res, text_mode=TextMode.text_raw, response_key="message")
display(res, text_mode=display.RAW, response_key="message")
4 changes: 2 additions & 2 deletions src/globus_cli/commands/endpoint/server/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from globus_cli.login_manager import LoginManager
from globus_cli.parsing import command, endpoint_id_arg
from globus_cli.termio import TextMode, display
from globus_cli.termio import display


def _spec_to_matches(
Expand Down Expand Up @@ -121,4 +121,4 @@ def server_delete(

response = transfer_client.delete_endpoint_server(endpoint_id, server)

display(response, text_mode=TextMode.text_raw, response_key="message")
display(response, text_mode=display.RAW, response_key="message")
Loading

0 comments on commit 19b2a18

Please sign in to comment.