|
25 | 25 | {self} [--path=<path>] [-v...] <target> gist fetch <gist> [<gist_file>]
|
26 | 26 | {self} [--path=<path>] [-v...] <target> gist create [--secret] <description> [<gist_path> <gist_path>...]
|
27 | 27 | {self} [--path=<path>] [-v...] <target> gist delete <gist> [-f]
|
| 28 | + {self} [--path=<path>] [-v...] <target> config [--config=<gitconfig>] |
| 29 | + {self} [-v...] config [--config=<gitconfig>] |
28 | 30 | {self} --help
|
29 | 31 |
|
30 | 32 | Tool for managing remote repository services.
|
|
38 | 40 | gist Manages gist files
|
39 | 41 | request Handles requests for merge
|
40 | 42 | open Open the given or current repository in a browser
|
| 43 | + config Run authentication process and configure the tool |
41 | 44 |
|
42 | 45 | Options:
|
43 | 46 | <user>/<repo> Repository to work with
|
@@ -239,6 +242,10 @@ def set_name(self, name):
|
239 | 242 | def set_gist_ref(self, gist):
|
240 | 243 | self.gist_ref = gist
|
241 | 244 |
|
| 245 | + @store_parameter('--config') |
| 246 | + def store_gitconfig(self, val): |
| 247 | + self.config = val or os.path.join(os.environ['HOME'], '.gitconfig') |
| 248 | + |
242 | 249 | '''Actions'''
|
243 | 250 |
|
244 | 251 | @register_action('add')
|
@@ -410,6 +417,58 @@ def do_gist_delete(self):
|
410 | 417 | log.info('Successfully deleted gist!')
|
411 | 418 | return 0
|
412 | 419 |
|
| 420 | + @register_action('config') |
| 421 | + def do_config(self): |
| 422 | + from getpass import getpass |
| 423 | + |
| 424 | + def loop_input(*args, method=input, **kwarg): |
| 425 | + out = '' |
| 426 | + while len(out) == 0: |
| 427 | + out = method(*args, **kwarg) |
| 428 | + return out |
| 429 | + |
| 430 | + def setup_service(service): |
| 431 | + conf = service.get_config(self.config) |
| 432 | + if 'token' in conf: |
| 433 | + raise Exception('A token has been generated for this service. Please revoke and delete before proceeding.') |
| 434 | + |
| 435 | + print('Please enter your credentials to connect to the service:') |
| 436 | + username = loop_input('username> ') |
| 437 | + password = loop_input('password> ', method=getpass) |
| 438 | + |
| 439 | + token = service.get_auth_token(username, password) |
| 440 | + print('Great! You\'ve been identified 🍻') |
| 441 | + |
| 442 | + print('Do you want to give a custom name for this service\'s remote?') |
| 443 | + if 'y' in input(' [yN]> ').lower(): |
| 444 | + print('Enter the remote\'s name:') |
| 445 | + loop_input('[{}]> '.format(service.name)) |
| 446 | + |
| 447 | + print('Do you want to configure a git alias?') |
| 448 | + print('N.B.: instead of typing `git repo {0}` you\'ll be able to type `git {0}`'.format(service.command)) |
| 449 | + if 'n' in input(' [Yn]> ').lower(): |
| 450 | + set_alias = False |
| 451 | + else: |
| 452 | + set_alias = True |
| 453 | + |
| 454 | + service.store_config(self.config, token=token) |
| 455 | + if set_alias: |
| 456 | + service.set_alias(self.config) |
| 457 | + |
| 458 | + if self.target: |
| 459 | + services = [self.get_service(lookup_repository=False)] |
| 460 | + else: |
| 461 | + services = RepositoryService.service_map.values() |
| 462 | + |
| 463 | + for service in services: |
| 464 | + print('Do you want to configure the {} service?'.format(service.name)) |
| 465 | + if 'n' in input(' [Yn]> ').lower(): |
| 466 | + continue |
| 467 | + setup_service(service) |
| 468 | + |
| 469 | + print('🍻 The configuration is done!') |
| 470 | + return 0 |
| 471 | + |
413 | 472 |
|
414 | 473 | def main(args):
|
415 | 474 | try:
|
|
0 commit comments