Skip to content

Commit

Permalink
Add an st2 pack show command
Browse files Browse the repository at this point in the history
  • Loading branch information
emedvedev committed Oct 6, 2016
1 parent 0170a16 commit e262603
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 17 additions & 1 deletion st2client/st2client/commands/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, description, app, subparsers, parent_parser=None):
self.commands['install'] = PackInstallCommand(self.resource, self.app, self.subparsers)
self.commands['remove'] = PackRemoveCommand(self.resource, self.app, self.subparsers)
self.commands['search'] = PackSearchCommand(self.resource, self.app, self.subparsers)
self.commands['show'] = PackShowCommand(self.resource, self.app, self.subparsers)


class PackResourceCommand(resource.ResourceCommand):
Expand Down Expand Up @@ -107,6 +108,21 @@ class PackListCommand(resource.ResourceListCommand):
attribute_display_order = ['name', 'description', 'version', 'author']


class PackShowCommand(PackResourceCommand):
def __init__(self, resource, *args, **kwargs):
super(PackShowCommand, self).__init__(resource, 'show',
'Get information about a %s from the index.' % resource.get_display_name().lower(),
*args, **kwargs)

self.parser.add_argument('name',
help='Name of the %s to show.' %
resource.get_display_name().lower())

@resource.add_auth_token_to_kwargs_from_cli
def run(self, args, **kwargs):
return self.manager.search(args, **kwargs)


class PackInstallCommand(PackAsyncCommand):
def __init__(self, resource, *args, **kwargs):
super(PackInstallCommand, self).__init__(resource, 'install',
Expand Down Expand Up @@ -186,4 +202,4 @@ def __init__(self, resource, *args, **kwargs):

@resource.add_auth_token_to_kwargs_from_cli
def run(self, args, **kwargs):
return self.manager.search(args.query, **kwargs)
return self.manager.search(args, **kwargs)
8 changes: 6 additions & 2 deletions st2client/st2client/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,13 @@ def create(self, name, **kwargs):
return instance

@add_auth_token_to_kwargs_from_env
def search(self, query, **kwargs):
def search(self, args, **kwargs):
url = '/%s/search' % (self.resource.get_url_path_name())
response = self.client.post(url, {'query': query})
if getattr(args, 'query'):
payload = {'query': args.query}
else:
payload = {'name': args.name}
response = self.client.post(url, payload)
if response.status_code != 200:
self.handle_error(response)
instance = self.resource.deserialize(response.json())
Expand Down

0 comments on commit e262603

Please sign in to comment.