-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.py
49 lines (41 loc) · 1.74 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import argparse
import os
from os import path
import sys
from . import __version__
# Setting Ansible config file environment variable as first thing
cwd = path.dirname(path.realpath(__file__))
os.environ['ANSIBLE_CONFIG'] = path.join(cwd, 'ansible.cfg')
os.environ['ANSIBLE_ROLES_PATH'] = path.join(cwd, 'roles') + os.pathsep + '/etc/ansible/roles'
os.environ['ANSIBLE_LOOKUP_PLUGINS'] = path.join(cwd, 'plugins', 'lookup') + os.pathsep + '/usr/share/ansible_plugins/lookup_plugins'
os.environ['ANSIBLE_LIBRARY'] = path.join(cwd, 'modules')
from digital_ocean import DigitalOceanCli
from local import LocalCli
from ssh import SshCli
from vagrant import VagrantCli
Providers = {
'local': LocalCli,
'ssh': SshCli,
'vagrant': VagrantCli,
'digital-ocean': DigitalOceanCli
}
class CLI(object):
def parse(self, args=None):
parser = argparse.ArgumentParser(prog='prudentia', description='A useful Continuous Deployment toolkit.')
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('provider', choices=Providers.keys(), help='use one of the available providers')
parser.add_argument('commands', nargs='*', default='',
help='optional quoted list of commands to run with the chosen provider')
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
return parser.parse_args(args)
def run(self, args):
chosen_cli = Providers[args.provider]()
if args.commands:
for c in args.commands:
print "Executing: '{0}'\n".format(c)
chosen_cli.onecmd(c)
else:
chosen_cli.cmdloop()
return chosen_cli.provider.provisioned