Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
add subcommand help dispatch, with placeholder help for now #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Monroy committed Jul 27, 2013
1 parent c3e907c commit af4b082
Showing 1 changed file with 78 additions and 5 deletions.
83 changes: 78 additions & 5 deletions client/deis.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def auth_register(self, args):

def auth_login(self, args):
"""
Authenticate a user in the system.
Login by authenticating against a controller
Usage: deis auth:login <controller> [--username=<username> --password=<password>]
"""
Expand Down Expand Up @@ -276,7 +276,11 @@ def auth_login(self, args):
return False

def auth_logout(self, args):
"""Clear a user's session and unauthenticate her."""
"""
Logout from a controller, clearing the user session
Usage: deis auth:logout
"""
controller = self._settings.get('controller')
if controller:
self._dispatch('get', '/api/auth/logout/')
Expand All @@ -286,6 +290,12 @@ def auth_logout(self, args):
self._settings.save()
print('Logged out')

def builds(self, args):
"""
Builds help would be nice
"""
return self.builds_list(args)

def builds_create(self, args):
"""
Usage: deis builds:create - [--formation=<formation>]
Expand Down Expand Up @@ -320,6 +330,12 @@ def builds_list(self, args):
else:
print('Error!', response.text)

def config(self, args):
"""
Config help would be nice
"""
return self.config_list(args)

def config_list(self, args):
"""
Usage: deis config:list
Expand Down Expand Up @@ -392,6 +408,12 @@ def config_unset(self, args):
else:
print('Error!', response.text)

def containers(self, args):
"""
Containers help would be nice
"""
return self.containers_list(args)

def containers_list(self, args):
"""
Usage: deis containers:list
Expand Down Expand Up @@ -437,6 +459,12 @@ def containers_scale(self, args):
else:
print('Error!', response.text)

def flavors(self, args):
"""
Flavors help would be nice
"""
return self.flavors_list(args)

def flavors_create(self, args):
"""
Usage: deis flavors:create --id=<id> --provider=<provider> --params=<params> [options]
Expand Down Expand Up @@ -493,6 +521,12 @@ def flavors_list(self, args):
else:
print('Error!', response.text)

def formations(self, args):
"""
Formations help would be nice
"""
return self.formations_list(args)

def formations_create(self, args):
"""
Usage: deis formations:create [--id=<id> --flavor=<flavor>]
Expand Down Expand Up @@ -638,6 +672,12 @@ def formations_converge(self, args):
else:
print('Error!', response.text)

def keys(self, args):
"""
Keys help would be nice
"""
return self.keys_list(args)

def keys_add(self, args):
"""
Usage: deis keys:add [<key>]
Expand Down Expand Up @@ -708,6 +748,12 @@ def keys_remove(self, args):
else:
print('Error!', response.text)

def layers(self, args):
"""
Layers help would be nice
"""
return self.layers_list(args)

def layers_create(self, args):
"""
Create a layer of nodes.
Expand Down Expand Up @@ -823,6 +869,12 @@ def nodes_info(self, args):
else:
print('Error!', response.text)

def nodes(self, args):
"""
Nodes help would be nice
"""
return self.nodes_list(args)

def nodes_list(self, args):
"""
List nodes for this formation.
Expand Down Expand Up @@ -862,6 +914,12 @@ def nodes_destroy(self, args):
else:
print('Error!', response.status_code, response.text)

def providers(self, args):
"""
Providers help would be nice
"""
return self.providers_list(args)

def providers_create(self, args):
"""
Create a provider for use by Deis
Expand Down Expand Up @@ -943,6 +1001,21 @@ def providers_info(self, args):
else:
print('Error!', response.text)

def releases_list(self, args):
"""
Usage: deis releases:list
"""
formation = args.get('--formation')
if not formation:
formation = self._session.formation
response = self._dispatch('get', '/formations/{}/release'.format(formation))
if response.status_code == requests.codes.ok: # @UndefinedVariable
print('=== {0}'.format(formation))
data = response.json()
for item in data['results']:
print('{0[uuid]:<23} {0[created]}'.format(item))
else:
print('Error!', response.text)

def main():
"""
Expand Down Expand Up @@ -982,12 +1055,12 @@ def main():
args.update(docopt(docstring))
# find the right method for dispatching
if cmd == 'help':
if len(sys.argv) == 3 and sys.argv[2] in dir(cli):
print trim(getattr(cli, sys.argv[2]).__doc__)
return
docopt(__doc__, argv=['--help'])
elif hasattr(cli, cmd):
method = getattr(cli, cmd)
# magically call list if no subcommand provided
elif hasattr(cli, cmd + '_list'):
method = getattr(cli, cmd + '_list')
else:
print 'Found no matching command'
raise DocoptExit()
Expand Down

0 comments on commit af4b082

Please sign in to comment.