Skip to content

Commit 9ec12b0

Browse files
author
Cameron Brandon White
committed
Added database command which launches psql
1 parent b3e1554 commit 9ec12b0

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

acmcli/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ def acmcli():
5656
officerships_list(acmlib, args)
5757
elif args.subparser2 == 'delete':
5858
officerships_delete(acmlib, args)
59+
elif args.subparser1 == 'database':
60+
database_get(acmlib, args)

acmcli/parser.py

+7
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,11 @@ def datetime_type(x):
193193

194194
officerships_delete_parser.add_argument('officership_id', type=int)
195195

196+
197+
#
198+
# Database Parser
199+
#
200+
201+
database_parser = subparsers.add_parser('database')
202+
196203
parser.parse_args()

acmcli/routines.py

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import os
23

34
def exit_with_message_on_errors(f):
45

@@ -234,3 +235,25 @@ def officerships_delete(acmlib, args):
234235

235236
acmlib.delete_officership(args.officership_id)
236237

238+
@exit_with_message_on_errors
239+
def database_get(acmlib, args):
240+
241+
database = acmlib.get_database();
242+
243+
command = "psql "
244+
if database.dilect:
245+
command += "{}://".format(database.dilect)
246+
if database.username:
247+
command += database.username
248+
if database.password:
249+
command += ":" + database.password
250+
command += "@"
251+
if database.host:
252+
command += database.host
253+
if database.port:
254+
command += ":" + str(database.port)
255+
if database.database:
256+
command += "/" + database.database
257+
258+
os.system(command)
259+

0 commit comments

Comments
 (0)