
-Added cli folder -Utilizes click to process commands -commands can be found at https://github.com/att-comdev/shipyard/blob/master/docs/CLI.md -also, running the command 'shipyard' will give you a brief description of the commands available -Contains actions.py that calls Client API -Added tests folder -Unit tests for commands -Negative unit tests are also included for commands -Unit tests for actions Change-Id: Ie3e4d1f18aa935a311f332fba5c8a4d239183469
48 lines
1.6 KiB
Python
48 lines
1.6 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-1.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.
|
|
|
|
import json
|
|
import yaml
|
|
|
|
|
|
def output_formatting(output_format, response):
|
|
"""formats response from api_client"""
|
|
if output_format == 'raw':
|
|
return response.text
|
|
else: # assume formatted
|
|
return formatted(response)
|
|
|
|
|
|
def formatted(response):
|
|
"""Formats either json or yaml depending on call"""
|
|
call = response.headers['Content-Type']
|
|
if 'json' in call:
|
|
try:
|
|
input = response.json()
|
|
return (json.dumps(input, sort_keys=True, indent=4))
|
|
except ValueError:
|
|
return ("This is not json and could not be printed as such. \n " +
|
|
response.text)
|
|
|
|
else: # all others should be yaml
|
|
try:
|
|
return (yaml.dump_all(
|
|
yaml.safe_load_all(response.content),
|
|
width=79,
|
|
indent=4,
|
|
default_flow_style=False))
|
|
except ValueError:
|
|
return ("This is not yaml and could not be printed as such.\n " +
|
|
response.text)
|