|
8 | 8 | Port {port}
|
9 | 9 | """
|
10 | 10 |
|
| 11 | + |
11 | 12 | def args_to_obj(args):
|
12 | 13 | return SSH_TEMPLATE.format(**args.__dict__)
|
13 | 14 |
|
| 15 | + |
14 | 16 | def add_to_conf(conf, obj):
|
15 | 17 | conf = os.path.expanduser(conf)
|
16 | 18 | with open(conf, 'a') as f:
|
17 | 19 | f.write(obj)
|
18 | 20 |
|
| 21 | + |
19 | 22 | def main():
|
20 |
| - parser = argparse.ArgumentParser(prog="Adds ssh hosts to the ssh config file.") |
| 23 | + parser = argparse.ArgumentParser( |
| 24 | + prog="Adds ssh hosts to the ssh config file.") |
21 | 25 | parser.add_argument('name', help="Name of the Host to add to the config.")
|
22 | 26 | parser.add_argument('hostname', help="Hostname/IP address of the host.")
|
23 |
| - parser.add_argument('--user', default='root', help="The user to connect with. Defaults to root.") |
24 |
| - parser.add_argument('--port', default=22, type=int, help="The port to connect to. Defaults to 22.") |
25 |
| - parser.add_argument('--conf', default='~/.ssh/config', help="The path to the ssh config file. Defaults to ~/.ssh/config.") |
| 27 | + parser.add_argument('--user', default='root', |
| 28 | + help="The user to connect with. Defaults to root.") |
| 29 | + parser.add_argument('--port', default=22, type=int, |
| 30 | + help="The port to connect to. Defaults to 22.") |
| 31 | + parser.add_argument('--conf', default='~/.ssh/config', |
| 32 | + help="The path to the ssh config file. Defaults to ~/.ssh/config.") |
26 | 33 |
|
27 | 34 | args = parser.parse_args()
|
28 | 35 | obj = args_to_obj(args)
|
29 | 36 | add_to_conf(args.conf, obj)
|
30 | 37 |
|
| 38 | + |
31 | 39 | if __name__ == '__main__':
|
32 | 40 | main()
|
0 commit comments