Skip to content

Commit 21f50dd

Browse files
committed
Limits the len of subnet name when displayed in cli commands
1 parent b04a791 commit 21f50dd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

bittensor_cli/src/bittensor/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,23 +1266,29 @@ def is_valid_contact(contact: str) -> bool:
12661266
return bool(re.match(email_pattern, contact))
12671267

12681268

1269-
def get_subnet_name(subnet_info) -> str:
1269+
def get_subnet_name(subnet_info, max_length: int = 20) -> str:
12701270
"""Get the subnet name, prioritizing subnet_identity.subnet_name over subnet.subnet_name.
1271+
Truncates the name if it exceeds max_length.
12711272
12721273
Args:
1273-
subnet: The subnet dynamic info
1274+
subnet_info: The subnet dynamic info
1275+
max_length: Maximum length of the returned name. Names longer than this will be truncated with '...'
12741276
12751277
Returns:
1276-
str: The subnet name or empty string if no name is found
1278+
str: The subnet name (truncated if necessary) or empty string if no name is found
12771279
"""
1278-
return (
1280+
name = (
12791281
subnet_info.subnet_identity.subnet_name
12801282
if hasattr(subnet_info, "subnet_identity")
12811283
and subnet_info.subnet_identity is not None
12821284
and subnet_info.subnet_identity.subnet_name is not None
12831285
else (subnet_info.subnet_name if subnet_info.subnet_name is not None else "")
12841286
)
12851287

1288+
if len(name) > max_length:
1289+
return name[: max_length - 3] + "..."
1290+
return name
1291+
12861292

12871293
def print_linux_dependency_message():
12881294
"""Prints the WebKit dependency message for Linux systems."""

0 commit comments

Comments
 (0)