One-Fine-Day f3188fcf10 Shipyard CLI for Configdocs Status
Shipyard API to discover buffered and committed collections of configdocs

3 of 4 Commits (API, API Client, Documentation are in separate commits)

CLI
-added action to the configdocs status in get/actions.py
-modified get configdocs command to accept the command without the collection
 in get/commands.py
-added table formating for the collections in cli_format_common.py
-unit tests are located in test_get_actions.py and test_get_commands.py

Change-Id: I29ad088c1dd0bdaccd8c5328abb610a1c32f99aa
2018-01-05 17:27:55 -06:00

172 lines
5.2 KiB
Python

# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Get command
import click
from shipyard_client.cli.get.actions import GetActions
from shipyard_client.cli.get.actions import GetConfigdocs
from shipyard_client.cli.get.actions import GetConfigdocsStatus
from shipyard_client.cli.get.actions import GetRenderedConfigdocs
from shipyard_client.cli.get.actions import GetWorkflows
@click.group()
@click.pass_context
def get(ctx):
"""
Get the actions, confidocs, or renderedconfigdocs. \n
For more information on get commands
please enter the get command followed by '--help' \n
Example: shipyard get actions --help
"""
DESC_ACTIONS = """
COMMAND: actions \n
DESCRIPTION: Lists the actions that have been invoked. \n
FORMAT: shipyard get actions \n
EXAMPLE: shipyard get actions
"""
SHORT_DESC_ACTIONS = "Lists the actions that have been invoked."
@get.command(name='actions', help=DESC_ACTIONS, short_help=SHORT_DESC_ACTIONS)
@click.pass_context
def get_actions(ctx):
click.echo(GetActions(ctx).invoke_and_return_resp())
DESC_CONFIGDOCS = """
COMMAND: configdocs \n
DESCRIPTION: Retrieve documents loaded into Shipyard, either committed or
from the Shipyard Buffer. \n
FORMAT: shipyard get configdocs <collection> [--committed | --buffer] \n
EXAMPLE: shipyard get configdocs design
"""
SHORT_DESC_CONFIGDOCS = ("Retrieve documents loaded into Shipyard, either "
"committed or from the Shipyard Buffer.")
@get.command(
name='configdocs', help=DESC_CONFIGDOCS, short_help=SHORT_DESC_CONFIGDOCS)
@click.argument('collection', nargs=-1, required=False)
@click.option(
'--committed',
'-c',
flag_value='committed',
help='Retrieve the documents that have last been committed for this '
'collection')
@click.option(
'--buffer',
'-b',
flag_value='buffer',
help='Retrive the documents that have been loaded into Shipyard since the '
'prior commit. If no documents have been loaded into the buffer for this '
'collection, this will return an empty response (default)')
@click.pass_context
def get_configdocs(ctx, collection, buffer, committed):
if collection:
if buffer and committed:
ctx.fail(
'You must choose whether to retrive the committed OR from the '
'Shipyard Buffer with --committed or --buffer. ')
if committed:
version = 'committed'
else:
version = 'buffer'
click.echo(
GetConfigdocs(ctx, collection, version).invoke_and_return_resp())
else:
click.echo(GetConfigdocsStatus(ctx).invoke_and_return_resp())
DESC_RENDEREDCONFIGDOCS = """
COMMAND: renderedconfigdocs \n
DESCRIPTION: Retrieve the rendered version of documents loaded into
Shipyard. Rendered documents are the "final" version of the documents after
applying Deckhand layering and substitution. \n
FORMAT: shipyard get renderedconfigdocs [--committed | --buffer] \n
EXAMPLE: shipyard get renderedconfigdocs
"""
SHORT_DESC_RENDEREDCONFIGDOCS = (
"Retrieve the rendered version of documents "
"loaded into Shipyard. Rendered documents are "
"the 'final' version of the documents after "
"applying Deckhand layering and substitution.")
@get.command(
name='renderedconfigdocs',
help=DESC_RENDEREDCONFIGDOCS,
short_help=SHORT_DESC_RENDEREDCONFIGDOCS)
@click.option(
'--committed',
'-c',
flag_value='committed',
help='Retrieve the documents that have last been committed.')
@click.option(
'--buffer',
'-b',
flag_value='buffer',
help='Retrieve the documents that have been loaded into Shipyard since the'
' prior commit. (default)')
@click.pass_context
def get_renderedconfigdocs(ctx, buffer, committed):
if buffer and committed:
ctx.fail(
'You must choose whether to retrive the committed documents OR the'
' docutments in the Shipyard Buffer with --committed or --buffer.')
if committed:
version = 'committed'
else:
version = 'buffer'
click.echo(GetRenderedConfigdocs(ctx, version).invoke_and_return_resp())
DESC_WORKFLOWS = """
COMMAND: workflows \n
DESCRIPTION: Lists the workflows from airflow. \n
FORMAT: shipyard get workflows [since]\n
EXAMPLE: \n
shipyard get workflows \n
shipyard get workflows --since=2017-11-09T15:02:18Z
"""
SHORT_DESC_WORKFLOWS = "Lists the workflows from airflow."
@get.command(
name='workflows', help=DESC_WORKFLOWS, short_help=SHORT_DESC_WORKFLOWS)
@click.option(
'--since',
help=('A boundary in the past within which to retrieve results.'
'Default is 30 days in the past.'))
@click.pass_context
def get_workflows(ctx, since):
click.echo(GetWorkflows(ctx, since).invoke_and_return_resp())