|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | | -"""Usage: deis <command> [--formation=<formation>] [<args>...] |
| 3 | +"""Usage: deis <command> [--formation <formation>] [<args>...] |
4 | 4 |
|
5 | 5 | Options: |
6 | 6 | -h --help Show this help screen |
@@ -207,6 +207,8 @@ def _dispatch(self, method, path, body=None, |
207 | 207 |
|
208 | 208 | def auth_register(self, args): |
209 | 209 | """ |
| 210 | + Register a new user with a Deis controller |
| 211 | +
|
210 | 212 | Usage: deis auth:register <controller> [--username=<username> --password=<password> --email=<email>] |
211 | 213 | """ |
212 | 214 | controller = args['<controller>'] |
@@ -485,52 +487,56 @@ def flavors_list(self, args): |
485 | 487 |
|
486 | 488 | def formations_create(self, args): |
487 | 489 | """ |
488 | | - Usage: deis formations:create --flavor=<flavor> [--image=<image> --id=<id>] |
| 490 | + Usage: deis formations:create [--flavor=<flavor> --id=<id>] |
489 | 491 | """ |
490 | 492 | body = {} |
491 | | - for opt in ('--id', '--image'): |
| 493 | + for opt in ('--id',): |
492 | 494 | o = args.get(opt) |
493 | 495 | if o: |
494 | 496 | body.update({opt.strip('-'): o}) |
| 497 | + sys.stdout.write('Creating formation... ') |
| 498 | + sys.stdout.flush() |
495 | 499 | response = self._dispatch('post', '/api/formations', |
496 | 500 | json.dumps(body)) |
497 | 501 | if response.status_code == requests.codes.created: # @UndefinedVariable |
498 | 502 | data = response.json() |
499 | 503 | formation = data['id'] |
500 | | - print('Created ' + formation) |
| 504 | + print 'done, created {}'.format(formation) |
| 505 | + # add a git remote |
501 | 506 | hostname = urlparse.urlparse(self._settings['controller']).netloc |
| 507 | + git_remote = 'git@{hostname}:{formation}.git'.format(**locals()) |
502 | 508 | try: |
503 | 509 | subprocess.check_call( |
504 | | - ['git', 'remote', 'add', '-f', 'deis', |
505 | | - 'git@{hostname}:{formation}.git'.format(**locals())]) |
| 510 | + ['git', 'remote', 'add', '-f', 'deis', git_remote], |
| 511 | + stdout=subprocess.PIPE) |
506 | 512 | except subprocess.CalledProcessError: |
507 | 513 | sys.exit(1) |
508 | | - print('Git remote added') |
| 514 | + print('Git remote deis added') |
509 | 515 | else: |
510 | 516 | print('Error!', response.text) |
511 | 517 |
|
512 | | - def formations_list(self, args): |
| 518 | + def formations_info(self, args): |
513 | 519 | """ |
514 | 520 | Usage: deis formations:info |
515 | 521 | """ |
516 | | - response = self._dispatch('get', '/api/formations') |
| 522 | + formation = args.get('<formation>') |
| 523 | + if not formation: |
| 524 | + formation = self._session.formation |
| 525 | + response = self._dispatch('get', '/api/formations/{}'.format(formation)) |
517 | 526 | if response.status_code == requests.codes.ok: # @UndefinedVariable |
518 | | - data = response.json() |
519 | | - for item in data['results']: |
520 | | - print('{0[id]:<23}'.format(item)) |
| 527 | + print(json.dumps(response.json(), indent=2)) |
521 | 528 | else: |
522 | 529 | print('Error!', response.text) |
523 | 530 |
|
524 | | - def formations_info(self, args): |
| 531 | + def formations_list(self, args): |
525 | 532 | """ |
526 | 533 | Usage: deis formations:list |
527 | 534 | """ |
528 | | - formation = args.get('<formation>') |
529 | | - if not formation: |
530 | | - formation = self._session.formation |
531 | | - response = self._dispatch('get', '/api/formations/{}'.format(formation)) |
| 535 | + response = self._dispatch('get', '/api/formations') |
532 | 536 | if response.status_code == requests.codes.ok: # @UndefinedVariable |
533 | | - print(json.dumps(response.json(), indent=2)) |
| 537 | + data = response.json() |
| 538 | + for item in data['results']: |
| 539 | + print('{0[id]:<23}'.format(item)) |
534 | 540 | else: |
535 | 541 | print('Error!', response.text) |
536 | 542 |
|
@@ -562,7 +568,7 @@ def formations_destroy(self, args): |
562 | 568 | subprocess.check_call( |
563 | 569 | ['git', 'remote', 'rm', 'deis'], |
564 | 570 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
565 | | - print('Git remote removed') |
| 571 | + print('Git remote deis removed') |
566 | 572 | except subprocess.CalledProcessError: |
567 | 573 | pass # ignore error |
568 | 574 | else: |
@@ -746,7 +752,11 @@ def layers_destroy(self, args): |
746 | 752 | print('Error!', response.text) |
747 | 753 |
|
748 | 754 | def layers_list(self, args): |
749 | | - """List layers for this formation.""" |
| 755 | + """ |
| 756 | + List layers for this formation. |
| 757 | +
|
| 758 | + Usage deis layers:list |
| 759 | + """ |
750 | 760 | formation = args.get('--formation') |
751 | 761 | if not formation: |
752 | 762 | formation = self._session.formation |
@@ -949,19 +959,25 @@ def main(): |
949 | 959 | docstring = trim(getattr(cli, cmd).__doc__) |
950 | 960 | if 'Usage: ' in docstring: |
951 | 961 | args.update(docopt(docstring)) |
952 | | - # dispatch based on primary command |
| 962 | + # find the right method for dispatching |
953 | 963 | if cmd == 'help': |
954 | 964 | docopt(__doc__, argv=['--help']) |
955 | 965 | elif hasattr(cli, cmd): |
956 | 966 | method = getattr(cli, cmd) |
957 | | - return method(args) |
958 | 967 | # magically call list if no subcommand provided |
959 | 968 | elif hasattr(cli, cmd + '_list'): |
960 | 969 | method = getattr(cli, cmd + '_list') |
961 | | - return method(args) |
962 | 970 | else: |
963 | 971 | print 'Found no matching command' |
964 | 972 | raise DocoptExit() |
| 973 | + # dispatch the CLI command |
| 974 | + try: |
| 975 | + method(args) |
| 976 | + except EnvironmentError as e: |
| 977 | + if e.message.startswith('Could not find deis remote'): |
| 978 | + print 'Could not find git remote for deis' |
| 979 | + raise DocoptExit() |
| 980 | + raise e |
965 | 981 |
|
966 | 982 |
|
967 | 983 | if __name__ == '__main__': |
|
0 commit comments