33# Author: Bandie Canis
44# License: 2-Clause BSD License
55
6- import sys , ssl , socket , os
6+ import sys , ssl , socket , os , getopt
77import configparser
88
99
@@ -14,12 +14,15 @@ certfile = None
1414keyfile = None
1515exitcode = 1
1616
17- def readConfig ( ):
17+ def init ( conf ):
1818
19- if (os .name == 'nt' ):
20- CONFIG = "ding.win.cfg"
19+ if (conf == None ):
20+ if (os .name == 'nt' ):
21+ CONFIG = "ding.win.cfg"
22+ else :
23+ CONFIG = "ding.cfg"
2124 else :
22- CONFIG = "ding.cfg"
25+ CONFIG = conf
2326
2427 cfg = configparser .ConfigParser ()
2528 try :
@@ -67,7 +70,7 @@ def send(conn, cmd):
6770 quit (exitcode )
6871
6972
70- def main ():
73+ def main (arg ):
7174 try :
7275 context = ssl .SSLContext (ssl .PROTOCOL_TLS )
7376 context .verify_mode = ssl .CERT_REQUIRED
@@ -85,7 +88,7 @@ def main():
8588
8689
8790 try :
88- send (conn , bytes (sys . argv [ 1 ], sys .stdin .encoding ))
91+ send (conn , bytes (arg [ 0 ], sys .stdin .encoding ))
8992 except IndexError :
9093 print (sys .argv [0 ], ": Missing argument.\n Syntax: " , sys .argv [0 ], " <COMMAND>" , file = sys .stderr )
9194 except ConnectionRefusedError :
@@ -98,7 +101,16 @@ def main():
98101
99102
100103if (__name__ == "__main__" ):
101- readConfig ()
102- main ()
103- quit (exitcode )
104+ try :
105+ conf = None
106+ opts , args = getopt .getopt (sys .argv [1 :], "c:" )
107+ for o , a in opts :
108+ if o == "-c" :
109+ conf = a
110+ init (conf )
111+ main (args )
112+ except getopt .GetoptError as e :
113+ print ("Error using options. Allowed options:\n -c [FILE] - Config file\n " )
114+ quit (2 )
104115
116+ quit (exitcode )
0 commit comments