summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/utils/command.py
diff options
context:
space:
mode:
Diffstat (limited to 'testapi/testapi-client/testapiclient/utils/command.py')
-rw-r--r--testapi/testapi-client/testapiclient/utils/command.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/testapi/testapi-client/testapiclient/utils/command.py b/testapi/testapi-client/testapiclient/utils/command.py
new file mode 100644
index 0000000..95f1fb0
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/utils/command.py
@@ -0,0 +1,39 @@
+from cliff import command
+
+from testapiclient.utils import url_parse
+
+
+class Command(command.Command):
+ def get_parser(self, prog_name):
+ parser = super(Command, self).get_parser(prog_name)
+ parser.add_argument('-u',
+ type=str,
+ help='Username for authentication')
+ parser.add_argument('-p',
+ type=str,
+ help='Password for authentication')
+
+ return parser
+
+ def show(self, request, response):
+ print ' '.join([request,
+ 'success' if response.status_code < 300
+ else 'failed: {}'.format(response.text)])
+
+
+class Lister(command.Command):
+
+ @staticmethod
+ def filter_by_name(url, parsed_args):
+ def query_url():
+ return url_parse.query_join(url, name=parsed_args.name)
+
+ return query_url() if parsed_args.name else url
+
+ def show(self, response):
+ print response.json() if response.status_code < 300 else response.text
+
+
+class ShowOne(command.Command):
+ def show(self, response):
+ print response.json() if response.status_code < 300 else response.text