def app_main(self):
# Backup original arguments for later parsing
args_src = sys.argv
# Parse our argument list
parser = argparse.ArgumentParser(description='Chat roulette python server')
parser.add_argument('-n', '--non-interactive', dest='noninteractive', action='store_const', const=True,
help='non-interactive mode of operation, command line only')
parser.add_argument('-r', '--attempts', dest='attempts', type=int, default=3,
help='number of attempts in non-interactive mode')
parser.add_argument('-l','--pid-lock', dest='pidlock', type=int, default=-1,
help='number of attempts for pidlock acquire')
parser.add_argument('--debug', dest='debug', action='store_const', const=True,
help='enables debug mode')
parser.add_argument('--verbose', dest='verbose', action='store_const', const=True,
help='enables verbose mode')
parser.add_argument('--force', dest='force', action='store_const', const=True, default=False,
help='forces some action')
parser.add_argument('commands', nargs=argparse.ZERO_OR_MORE, default=[],
help='commands to process')
self.args = parser.parse_args(args=args_src[1:])
self.noninteractive = self.args.noninteractive
# Fixing cmd2 arg parsing, call cmdLoop
sys.argv = [args_src[0]]
for cmd in self.args.commands:
sys.argv.append(cmd)
# Terminate after execution is over on the non-interactive mode
if self.noninteractive:
sys.argv.append('quit')
if self.args.debug:
coloredlogs.install(level=logging.DEBUG)
self.cmdloop()
sys.argv = args_src
# Noninteractive - return the last result from the operation (for scripts)
if self.noninteractive:
sys.exit(self.last_result)
评论列表
文章目录