use getopt parser for command-line arguments

This commit is contained in:
f97ada87 2017-09-24 07:42:15 +10:00
parent aaa5e9d309
commit c89d86a779
No known key found for this signature in database
GPG Key ID: 07B327EEF97ADA87

View File

@ -29,6 +29,7 @@ from struct import pack
from subprocess import call
from time import sleep
from random import randint
import getopt
from api import MySimpleXMLRPCRequestHandler, StoppableXMLRPCServer
from helper_startup import isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections
@ -199,12 +200,25 @@ class Main:
def start(self, daemon=False):
_fixSocket()
shared.daemon = daemon
try:
opts, args = getopt.getopt(sys.argv[1:], "hcd",
["help", "curses", "daemon"])
# get curses flag
if '-c' in sys.argv:
except getopt.GetoptError:
self.usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
self.usage()
sys.exit()
elif opt in ("-d", "--daemon"):
daemon = True
elif opt in ("-c", "--curses"):
state.curses = True
shared.daemon = daemon
# is the application already running? If yes then exit.
shared.thisapp = singleinstance("", daemon)
@ -362,6 +376,17 @@ class Main:
signal.signal(signal.SIGTERM, helper_generic.signal_handler)
# signal.signal(signal.SIGINT, signal.SIG_DFL)
def usage(self):
print 'Usage: ' + sys.argv[0] + ' [OPTIONS]'
print '''
Options:
-h, --help show this help message and exit
-c, --curses use curses (text mode) interface
-d, --daemon run in daemon (background) mode
All parameters are optional.
'''
def stop(self):
with shared.printLock:
print('Stopping Bitmessage Deamon.')