Improve handling of local connections in CLI

1. Ensure the local connection is actually always present if it exists,
and stored in the store file.

2. Remove any invalid "local" store entries if present (i.e.
pvcapid.yaml entries from legacy versions).

3. Order the connection lists such that "local" is always first.

4. Improve pretty list output format such that all fields are wider if
needed
This commit is contained in:
Joshua Boniface 2024-10-17 09:48:57 -04:00
parent 861fef91e3
commit 7c8c71dff7
3 changed files with 14 additions and 5 deletions

View File

@ -905,7 +905,7 @@ def cli_connection_list_format_pretty(CLI_CONFIG, data):
# Parse each connection and adjust field lengths # Parse each connection and adjust field lengths
for connection in data: for connection in data:
for field, length in [(f, fields[f]["length"]) for f in fields]: for field, length in [(f, fields[f]["length"]) for f in fields]:
_length = len(str(connection[field])) _length = len(str(connection[field])) + 1
if _length > length: if _length > length:
length = len(str(connection[field])) + 1 length = len(str(connection[field])) + 1
@ -1005,7 +1005,7 @@ def cli_connection_detail_format_pretty(CLI_CONFIG, data):
# Parse each connection and adjust field lengths # Parse each connection and adjust field lengths
for connection in data: for connection in data:
for field, length in [(f, fields[f]["length"]) for f in fields]: for field, length in [(f, fields[f]["length"]) for f in fields]:
_length = len(str(connection[field])) _length = len(str(connection[field])) + 1
if _length > length: if _length > length:
length = len(str(connection[field])) + 1 length = len(str(connection[field])) + 1

View File

@ -167,9 +167,17 @@ def get_store(store_path):
with open(store_file) as fh: with open(store_file) as fh:
try: try:
store_data = jload(fh) store_data = jload(fh)
return store_data
except Exception: except Exception:
return dict() store_data = dict()
if path.exists(DEFAULT_STORE_DATA["cfgfile"]):
if store_data.get("local", None) != DEFAULT_STORE_DATA:
del store_data["local"]
if "local" not in store_data.keys():
store_data["local"] = DEFAULT_STORE_DATA
update_store(store_path, store_data)
return store_data
def update_store(store_path, store_data): def update_store(store_path, store_data):

View File

@ -68,7 +68,8 @@ def cli_connection_list_parser(connections_config, show_keys_flag):
} }
) )
return connections_data # Return, ensuring local is always first
return sorted(connections_data, key=lambda x: (x.get("name") != "local"))
def cli_connection_detail_parser(connections_config): def cli_connection_detail_parser(connections_config):