- Added a new server module for the Nest workspace, integrating with UVM's API. - Updated project description to reflect the new Nest functionality. - Created tests for the Nest server and CLI, ensuring proper functionality and error handling. - Refactored existing UVM server code to separate Nest and UVM functionalities. - Removed the old UVM dashboard assets package as it is now part of the Nest workspace. - Enhanced error messages for clarity regarding server shutdown commands.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Command-line entry point for the Nest workspace server."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from collections.abc import Sequence
|
|
|
|
from uvm.app import build_application
|
|
from uvm.errors import UvmError
|
|
|
|
|
|
def build_parser() -> argparse.ArgumentParser:
|
|
parser = argparse.ArgumentParser(
|
|
prog="nest",
|
|
description="Nest dashboard and local machine management workspace.",
|
|
allow_abbrev=False,
|
|
)
|
|
parser.add_argument("--serve", action="store_true", help="launch the Nest workspace server")
|
|
parser.add_argument("--host", default="127.0.0.1", help="bind address (default: 127.0.0.1)")
|
|
parser.add_argument("--port", type=int, default=8000, help="bind port (default: 8000)")
|
|
return parser
|
|
|
|
|
|
def main(argv: Sequence[str] | None = None) -> int:
|
|
parser = build_parser()
|
|
args = parser.parse_args(argv)
|
|
if not args.serve:
|
|
parser.error("--serve is required to launch the Nest workspace")
|
|
if not 1 <= args.port <= 65535:
|
|
parser.error("--port must be between 1 and 65535")
|
|
|
|
try:
|
|
from .server import run_server
|
|
|
|
application = build_application(emit=lambda message: print(message, file=sys.stderr))
|
|
run_server(application, host=args.host, port=args.port)
|
|
return 0
|
|
except UvmError as error:
|
|
print(f"nest: error: {error}", file=sys.stderr)
|
|
return 1
|
|
except KeyboardInterrupt:
|
|
print("nest: interrupted", file=sys.stderr)
|
|
return 130
|