-
Notifications
You must be signed in to change notification settings - Fork 54
/
cli.py
53 lines (40 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
50
51
52
53
from optparse import OptionParser
import sys
class CLI(object):
def __init__(self):
self.__config_parser()
def __config_parser(self):
self.__parser = OptionParser()
self.__parser.add_option("-v", "--version",
dest="schema_version",
default=None,
help="Schema version to migrate to. If not provided will migrate to the last version available.")
self.__parser.add_option("-c", "--config",
dest="db_config_file",
default="simple-db-migrate.conf",
help="Use specific config file. If not provided, will use simple-db-migrate.conf that is located in the current directory.")
self.__parser.add_option("-d", "--dir",
dest="migrations_dir",
default=".",
help="Find migration files in a specific directory. If not provided will search for files in the current directory.")
self.__parser.add_option("--showsql",
action="store_true",
dest="show_sql",
default=False,
help="Show all SQL statements executed.")
self.__parser.add_option("--create",
dest="create_migration",
default=None,
help="Create migration file with given nickname.")
def get_parser(self):
return self.__parser
def parse(self):
return self.__parser.parse_args()
def error_and_exit(self, msg):
print "[ERROR] %s\n" % (msg)
sys.exit(1)
def info_and_exit(self, msg):
print "%s\n" % (msg)
sys.exit(0)
def msg(self, msg):
print msg