diff --git a/src/malls/__main__.py b/src/malls/__main__.py index efc5c48..eee31c2 100644 --- a/src/malls/__main__.py +++ b/src/malls/__main__.py @@ -15,15 +15,19 @@ def configure_argument_parser(parser: argparse.ArgumentParser, subparser: bool = Users must choose EITHER file I/O OR TCP socket mode (mutually exclusive). """ + description = """ + MAL Language server. + By default uses STDI/O. + """ if subparser: - subparser = argparse.ArgumentParser("mal-ls", "MAL Language Server") + subparser = argparse.ArgumentParser(prog="mal-ls", description=description) parser.add_subparsers().add_parser(subparser) parser = subparser else: - parser.description = "MAL Language Server" + parser.description = description # ---- Mutually Exclusive Group: File I/O vs. TCP Socket ---- - mode_group = parser.add_mutually_exclusive_group(required=True) + mode_group = parser.add_mutually_exclusive_group() # File I/O file_group = mode_group.add_argument_group("File I/O", "Use file-based communication") @@ -60,8 +64,12 @@ def configure_argument_parser(parser: argparse.ArgumentParser, subparser: bool = help="Port to bind the TCP server to (default: 8080).", ) - mode_group.add_argument("--stdio", action="store_true", help="Use stdio") - mode_group.add_argument("--tcp", action="store_true", help="Use TCP mode") + mode_group.add_argument( + "--stdio", action=argparse.BooleanOptionalAction, default=True, help="Use stdio" + ) + mode_group.add_argument( + "--tcp", action=argparse.BooleanOptionalAction, default=False, help="Use TCP mode" + ) # Loggin logging = parser.add_argument_group("Logging", "Configure logging options") @@ -92,7 +100,7 @@ def fileio(args: argparse.Namespace): def uses_tcpsocket(args: argparse.Namespace) -> bool: - return bool(args.tcp or args.host or args.port) + return args.tcp def tcpsocket(args: argparse.Namespace): @@ -150,12 +158,14 @@ def main(args: argparse.Namespace | None = None): configure_logging(args) - if uses_fileio(args): - i, o = fileio(args) - start_fileio_server(i, o) - elif uses_tcpsocket(args): + # Default to STDI/O + if uses_tcpsocket(args): i, o = tcpsocket(args) start_fileio_server(i, o) + else: + # In case a check is needed, use `uses_fileio(args)` + i, o = fileio(args) + start_fileio_server(i, o) if __name__ == "__main__": diff --git a/tests/integration/test_base_protocol.py b/tests/integration/test_base_protocol.py index 4d9d5dd..7c6b3ba 100644 --- a/tests/integration/test_base_protocol.py +++ b/tests/integration/test_base_protocol.py @@ -30,9 +30,6 @@ def close(self): self.steps -= 1 -# TODO: create fake endpoint class (or similar) so the input can be stepped - - # https://github.com/python-lsp/python-lsp-server/blob/develop/pylsp/python_lsp.py#L58 def server_output( input: typing.BinaryIO, timeout: float | None = MAX_TIMEOUT