Skip to content

Commit

Permalink
[Storage] Truncate long command str in sky storage ls (#2177)
Browse files Browse the repository at this point in the history
* add command truncation for storage ls

* lint

* Add -a flag

* linting
  • Loading branch information
romilbhardwaj authored Jul 12, 2023
1 parent dc60afd commit 2bdec2a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
13 changes: 10 additions & 3 deletions sky/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3240,11 +3240,18 @@ def storage():


@storage.command('ls', cls=_DocumentedCodeCommand)
@click.option('--all',
'-a',
default=False,
is_flag=True,
required=False,
help='Show all information in full.')
@usage_lib.entrypoint
def storage_ls():
"""List storage objects created."""
# pylint: disable=redefined-builtin
def storage_ls(all: bool):
"""List storage objects managed by SkyPilot."""
storages = sky.storage_ls()
storage_table = storage_utils.format_storage_table(storages)
storage_table = storage_utils.format_storage_table(storages, show_all=all)
click.echo(storage_table)


Expand Down
13 changes: 10 additions & 3 deletions sky/data/storage_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

from sky import sky_logging
from sky.utils import log_utils
from sky.utils.cli_utils import status_utils

logger = sky_logging.init_logger(__name__)


def format_storage_table(storages: List[Dict[str, Any]]) -> str:
def format_storage_table(storages: List[Dict[str, Any]],
show_all: bool = False) -> str:
"""Format the storage table for display.
Args:
Expand All @@ -26,15 +28,20 @@ def format_storage_table(storages: List[Dict[str, Any]]) -> str:

for row in storages:
launched_at = row['launched_at']
if show_all:
command = row['last_use']
else:
command = status_utils.truncate_long_string(
row['last_use'], status_utils.COMMAND_TRUNC_LENGTH)
storage_table.add_row([
# NAME
row['name'],
# LAUNCHED
log_utils.readable_time_duration(launched_at),
# CLOUDS
', '.join([s.value for s in row['store']]),
# COMMAND
row['last_use'],
# COMMAND,
command,
# STATUS
row['status'].value,
])
Expand Down
10 changes: 5 additions & 5 deletions sky/utils/cli_utils/status_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sky.utils import common_utils
from sky.utils import log_utils

_COMMAND_TRUNC_LENGTH = 25
COMMAND_TRUNC_LENGTH = 25
NUM_COST_REPORT_LINES = 5

# A record in global_user_state's 'clusters' table.
Expand All @@ -21,7 +21,7 @@
_ClusterCostReportRecord = Dict[str, Any]


def _truncate_long_string(s: str, max_length: int = 35) -> str:
def truncate_long_string(s: str, max_length: int = 35) -> str:
if len(s) <= max_length:
return s
splits = s.split(' ')
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self,
def calc(self, record):
val = self.calc_func(record)
if self.trunc_length != 0:
val = _truncate_long_string(str(val), self.trunc_length)
val = truncate_long_string(str(val), self.trunc_length)
return val


Expand All @@ -82,7 +82,7 @@ def show_status_table(cluster_records: List[_ClusterRecord],
StatusColumn('AUTOSTOP', _get_autostop),
StatusColumn('COMMAND',
_get_command,
trunc_length=_COMMAND_TRUNC_LENGTH if not show_all else 0),
trunc_length=COMMAND_TRUNC_LENGTH if not show_all else 0),
]

columns = []
Expand Down Expand Up @@ -268,7 +268,7 @@ def show_local_status_table(local_clusters: List[str]):
# RESOURCES
resources_str,
# COMMAND
_truncate_long_string(command_str, _COMMAND_TRUNC_LENGTH),
truncate_long_string(command_str, COMMAND_TRUNC_LENGTH),
]
names.append(cluster_name)
cluster_table.add_row(row)
Expand Down

0 comments on commit 2bdec2a

Please sign in to comment.