Allow raw listing of cluster names in CLI

This commit is contained in:
Joshua Boniface 2021-07-09 10:53:20 -04:00
parent 80fe96b24d
commit 3f5b7045a2
1 changed files with 46 additions and 38 deletions

View File

@ -251,7 +251,11 @@ def cluster_remove(name):
# pvc cluster list # pvc cluster list
############################################################################### ###############################################################################
@click.command(name='list', short_help='List all available clusters.') @click.command(name='list', short_help='List all available clusters.')
def cluster_list(): @click.option(
'-r', '--raw', 'raw', is_flag=True, default=False,
help='Display the raw list of cluster names only.'
)
def cluster_list(raw):
""" """
List all the available PVC clusters configured in this CLI instance. List all the available PVC clusters configured in this CLI instance.
""" """
@ -302,6 +306,7 @@ def cluster_list():
if _api_key_length > api_key_length: if _api_key_length > api_key_length:
api_key_length = _api_key_length api_key_length = _api_key_length
if not raw:
# Display the data nicely # Display the data nicely
click.echo("Available clusters:") click.echo("Available clusters:")
click.echo() click.echo()
@ -341,6 +346,7 @@ def cluster_list():
if not api_key: if not api_key:
api_key = 'N/A' api_key = 'N/A'
if not raw:
click.echo( click.echo(
'{bold}{name: <{name_length}} {description: <{description_length}} {address: <{address_length}} {port: <{port_length}} {scheme: <{scheme_length}} {api_key: <{api_key_length}}{end_bold}'.format( '{bold}{name: <{name_length}} {description: <{description_length}} {address: <{address_length}} {port: <{port_length}} {scheme: <{scheme_length}} {api_key: <{api_key_length}}{end_bold}'.format(
bold='', bold='',
@ -359,6 +365,8 @@ def cluster_list():
api_key_length=api_key_length api_key_length=api_key_length
) )
) )
else:
click.echo(cluster)
# Validate that the cluster is set for a given command # Validate that the cluster is set for a given command