[FIX] Socket-mode port has not been added to the argument list. Fix: #34

This commit is contained in:
Benedek Racz 2020-03-30 09:31:31 +02:00
parent 08e2ffa109
commit a3acabda73

View File

@ -1,6 +1,7 @@
import argparse import argparse
import sys import sys
import logging import logging
import traceback
import wexpect.console_reader as console_reader import wexpect.console_reader as console_reader
import wexpect.wexpect_util as wexpect_util import wexpect.wexpect_util as wexpect_util
@ -20,38 +21,54 @@ def str2bool(v):
raise argparse.ArgumentTypeError('Boolean value expected.') raise argparse.ArgumentTypeError('Boolean value expected.')
def main(): def main():
parser = argparse.ArgumentParser(description='Wexpect: executable automation for Windows.') try:
parser = argparse.ArgumentParser(description='Wexpect: executable automation for Windows.')
parser.add_argument('--console_reader_class', type=str, parser.add_argument('--console_reader_class', type=str,
help='Class name of the console reader class.') help='Class name of the console reader class.')
parser.add_argument('command', type=str, nargs='+', help='Command to be run with its arguments') parser.add_argument('command', type=str, nargs='+', help='Command to be run with its arguments')
parser.add_argument('--host_pid', type=int, help='Host process process ID') parser.add_argument('--host_pid', type=int, help='Host process process ID')
parser.add_argument('--codepage', type=str, help='Codepage') parser.add_argument('--codepage', type=str, help='Codepage')
parser.add_argument('--window_size_x', type=int, help='Width of the console window', default=80) parser.add_argument('--window_size_x', type=int, help='Width of the console window', default=80)
parser.add_argument('--window_size_y', type=int, help='Height of the console window', default=25) parser.add_argument('--window_size_y', type=int, help='Height of the console window', default=25)
parser.add_argument('--buffer_size_x', type=int, help='Width of the console buffer', default=80) parser.add_argument('--buffer_size_x', type=int, help='Width of the console buffer', default=80)
parser.add_argument('--buffer_size_y', type=int, help='Height of the console buffer', parser.add_argument('--buffer_size_y', type=int, help='Height of the console buffer',
default=16000) default=16000)
parser.add_argument('--local_echo', type=str, help='Echo sent characters', default=True) parser.add_argument('--local_echo', type=str, help='Echo sent characters', default=True)
parser.add_argument('--interact', type=str, help='Show console window', default=False) parser.add_argument('--interact', type=str, help='Show console window', default=False)
args = parser.parse_args() parser.add_argument('--port', type=int, help=
logger.info(f'Starter arguments: {args}') "If the console reader class is SpawnSocket, this option specifies the "
"socket's port.", default=False)
if args.console_reader_class == 'ConsoleReaderSocket': try:
conole_reader_class = console_reader.ConsoleReaderSocket args = parser.parse_args()
elif args.console_reader_class == 'ConsoleReaderPipe': except SystemExit:
conole_reader_class = console_reader.ConsoleReaderPipe logger.error('Unexpected exception.')
logger.info(traceback.format_exc())
raise
command = wexpect_util.join_args(args.command) logger.info(f'Starter arguments: {args}')
cons = conole_reader_class( if args.console_reader_class == 'ConsoleReaderSocket':
path=command, host_pid=args.host_pid, codepage=args.codepage, conole_reader_class = console_reader.ConsoleReaderSocket
window_size_x=args.window_size_x, window_size_y=args.window_size_y, elif args.console_reader_class == 'ConsoleReaderPipe':
buffer_size_x=args.buffer_size_x, buffer_size_y=args.buffer_size_y, conole_reader_class = console_reader.ConsoleReaderPipe
local_echo=str2bool(args.local_echo), interact=str2bool(args.interact))
sys.exit(cons.child_exitstatus) command = wexpect_util.join_args(args.command)
cons = conole_reader_class(
path=command, host_pid=args.host_pid, codepage=args.codepage, port=args.port,
window_size_x=args.window_size_x, window_size_y=args.window_size_y,
buffer_size_x=args.buffer_size_x, buffer_size_y=args.buffer_size_y,
local_echo=str2bool(args.local_echo), interact=str2bool(args.interact))
sys.exit(cons.child_exitstatus)
except Exception as e:
logger.error('Unexpected exception.')
logger.info(traceback.format_exc())
raise
if __name__ == "__main__": if __name__ == "__main__":
main() main()